Using VC ++ and Open CV. Here's what I'm trying to do: find the first three horizontal-horizontal lines and draw them. find all almost vertical lines and draw them if any vertical line is above the horizontal line, then FLAG is set to 0 if there is no vertical Hough line above (all below) the horizontal line, then FLAG = 1
int n, i,c=0;
int flag = 0;
cvCanny( src, dst, 50, 150, 3 );
lines = cvHoughLines2( dst, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 10, 5, 5 );
n = lines->total;
for( i = 0; i < n; i++ )
{
CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
CvPoint pt1, pt2, hpt1, hpt2, vpt1, vpt2;
int hy = 0, vy = 0;
pt1 = line[0];
pt2 = line[1];
theta = atan( (double)(pt2.y - pt1.y)/(pt2.x - pt1.x) );
degree = theta*180/CV_PI;
if( fabs(degree) < 8)
{
c++;
if( c > 0 && c <5)
{
cvLine( out, pt1, pt2, CV_RGB(255, 255,255), 1, CV_AA, 0 );
hpt1 = line[0];
hpt2 = line[1];
if( hpt1.y > hpt2.y )
hy = hpt1.y;
else
hy = hpt2.y;
}
}
if( fabs(degree) > 70 )
{
cvLine( out, pt1, pt2, CV_RGB(255, 255,255), 1, CV_AA, 0 );
vpt1 = line[0];
vpt2 = line[1];
if( vpt1.y > vpt2.y )
vy = vpt1.y;
else
vy = vpt2.y;
if( vy >= hy )
flag = 1;
else
flag = 0;
}
}
display( out, "hough lines" );
return flag;
}
However, for an image, even if vertical lines are detected above the horizontal line, until the flag returns 1. So what am I calculating on the axis incorrectly? Please help me.