Skip to content

Instantly share code, notes, and snippets.

@ochilab
Last active December 18, 2015 18:59
Show Gist options
  • Save ochilab/5829256 to your computer and use it in GitHub Desktop.
Save ochilab/5829256 to your computer and use it in GitHub Desktop.
画像の中の横の直線を調べる(レポートスキャンシステム用)
private: void CheckHLine( Bitmap^ map ) {
int i , j , k , x , y , bure ;
int zahyoux[2500] , zahyouy[2500] ;
int point ;
Color col0 , col1 , col2 , col3 , col4 , col5 , col6 ;
int count = 0 ;
System::Drawing::Pen myPen( System::Drawing::Color::Red , 5 ) ;
if( map->Height == 0 || map->Width == 0 )//絵が何もない 不要?
{
return ;
}
else{
for( j = 20 ; j < map->Height - 20 ; j++ ){
for( i = 20 ; i < map->Width - 20 ; i++ ){
col0 = map->GetPixel( i , j ) ;
if( col0.R < 50 && col0.G < 50 && col0.B < 50 )//黒色なら左側を調べる
{
//count=count+1;
col1 = map->GetPixel( i - 1 , j - 1 ) ;
col2 = map->GetPixel( i - 1 , j ) ;
col3 = map->GetPixel( i - 1 , j + 1 ) ;
if( col1.R != 0 && col1.G != 0 && col1.B != 0
&& col2.R != 0 && col2.G != 0 && col2.B != 0
&& col3.R != 0 && col3.G != 0 && col3.B != 0 )//すべて黒色でなければ
{
x = i ;
y = j ;
point = 0 ;
zahyoux[point] = x ;
zahyouy[point] = y ;
while(1)
{
col4 = map->GetPixel( x + 1 , y ) ;
col5 = map->GetPixel( x + 1 , y - 1 ) ;
col6 = map->GetPixel( x + 1 , y + 1 ) ;//右側を調べる
if( col4.R < 50 && col4.G < 50 && col4.B < 50 )//真横が黒色ならそこへ移動
{
x++ ;
}
else if( col5.R < 50 && col5.G < 50 && col5.B < 50 )//右上が黒色ならそこへ移動 {
x++ ;
y-- ;
}
else if( col6.R < 50 && col6.G < 50 && col6.B < 50 )//右下が黒色ならそこへ移動
{
x++ ;
y++ ;
}
else//右側が黒でなければ終了
{
break ;
}
point = point + 1 ;
zahyoux[point] = x ;
zahyouy[point] = y ;
}
if( y > j )//始点と終点のブレを調べる
{
bure = y - j ;
}
else
{
bure = j - y ;
}
if( point > 100 && bure < 10 )//ある程度長くてブレが小さければ赤色にする
{
for( k = 0 ; k <= point ; k++ )
{
map->SetPixel( zahyoux[k] , zahyouy[k] ,System::Drawing::Color::Red ) ;
map->SetPixel( zahyoux[k] , zahyouy[k] - 1 ,System::Drawing::Color::Red ) ;
map->SetPixel( zahyoux[k] , zahyouy[k] - 2 ,System::Drawing::Color::Red ) ;
map->SetPixel( zahyoux[k] , zahyouy[k] + 1 ,System::Drawing::Color::Red ) ;
map->SetPixel( zahyoux[k] , zahyouy[k] + 2 ,System::Drawing::Color::Red ) ;
}
count = count + 1 ;
i = zahyoux[k] ;
}
}
}
}
}
fs->Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment