Skip to content

Instantly share code, notes, and snippets.

@ochilab
Created June 21, 2013 06:28
Show Gist options
  • Save ochilab/5829275 to your computer and use it in GitHub Desktop.
Save ochilab/5829275 to your computer and use it in GitHub Desktop.
縦の直線を調べる(レポートスキャンシステム用)
private: void CheckVline(Bitmap^ map)
{
int i , j , k , x , y , bure ;
int zahyoux[3600] , zahyouy[3600] ;
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( i = 20 ; i < map->Width - 20 ; i++ )
{
for( j = 20 ; j < map->Height - 20 ; j++ )
{
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 , j - 1 ) ;
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] = i ;
zahyouy[point] = j ;
while(1)
{
col4=map->GetPixel( x , y + 1 ) ;
col5=map->GetPixel( x + 1 , y + 1 ) ;
col6=map->GetPixel( x - 1 , y + 1 ) ;//下側を調べる
if( col4.R < 50 && col4.G < 50 && col4.B < 50 )//真下が黒色ならそこへ移動
{
y++ ;
}
else if( col5.R < 50 && col5.G < 50 && col5.B < 50 )//右下が黒色ならそこへ移動
{
y++ ;
x++ ;
}
else if( col6.R < 50 && col6.G < 50 && col6.B < 50 )//左下が黒色ならそこへ移動
{
y++ ;
x-- ;
}
else//下側が黒でなければ終了
{
break ;
}
point = point + 1 ;
zahyoux[point] = x ;
zahyouy[point] = y ;
}
if( x > i )//ブレを調べる
{
bure = x - i ;
}
else
{
bure = i - x ;
}
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] - 1 , zahyouy[k] , System::Drawing::Color::Red ) ;
map->SetPixel( zahyoux[k] - 2 , zahyouy[k] , System::Drawing::Color::Red ) ;
map->SetPixel( zahyoux[k] + 1 , zahyouy[k] , System::Drawing::Color::Red ) ;
map->SetPixel( zahyoux[k] + 2 , zahyouy[k] , System::Drawing::Color::Red ) ;
}
count = count + 1 ;
j = zahyouy[k] ;
}
}
}
}
}
fs->Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment