This was initially found by Paul
through Opencv community website.
Need to appreciate to Paul.
Example codes on the document of Opencv
is something wrong.
They can be corrected as below.
lines = cvHoughLines2(dst,storage,CV_HOUGH_STANDARD,rho,theta,50,0,0 );
for( i = 0; i <
lines->total; i++ )
{
line = (float*)cvGetSeqElem(lines,i);
rho = line[0];
theta = line[1];
// if(ThreshSingleLine<)
a = cos(theta), b = sin(theta), c =
tan(theta);
if( fabs(b) < 0.001 )
{
pt1.x = pt2.x = cvRound(rho);
pt1.y = 0;
pt2.y = dst->height;
}
else if( fabs(a) < 0.001 )
{
pt1.y = pt2.y = cvRound(rho);
pt1.x = 0;
pt2.x = dst->width;
}
else
{
pt1.x = 0;
pt1.y = cvRound(rho/b);
if(pt1.y < 0)
{
pt1.x = cvRound(rho / a);
pt1.y = 0;
}
if(pt1.y >dst->height)
{
pt1.x = cvRound((pt1.y - dst->height)*c);
pt1.y = dst->height;
}
pt2.x = dst->width;
pt2.y = cvRound(rho/b
- dst->width/c);
if(pt2.y < 0)
{
pt2.x = cvRound(rho/a);
pt2.y = 0;
}
if(pt2.y > dst->height)
{
pt2.x = cvRound(-1.0 * ((dst->height - rho/b) * c));
pt2.y = dst->height;
}
}
cvLine(Source, pt1, pt2, CV_RGB(100,0,0),
1 , 8, 0 );
}
Samuel