I have a vector of lines produced by calling hough transformation function in Opencv, and need to convert them back to image coordinates. I found this piece of sample code from Opencv's official documentation, but I don't understand it. Would any one explain please?
for( size_t i = 0; i < lines->size(); i++ )
{
float rho = lines->at(i)[0]; //[0] is rho
float theta = lines->at(i)[1]; //[1] is theta
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
cv::Point pt1(cvRound(x0 + 1000*(-b)),
cvRound(y0 + 1000*(a)));
cv::Point pt2(cvRound(x0 - 1000*(-b)),
cvRound(y0 - 1000*(a)));
line( *mat, pt1, pt2, Scalar(255,0,0), 1, 8 );
}
What is the 1000 doing this line?
pt1(cvRound(x0 + 1000*(-b)), cvRound(y0 + 1000*(a)))
Furthermore, why does pt2 have negative y cords? For example, if my first line is (0,0) in (rho, theta) format, pt2 would be (0, -1000).
Thanks,
That's how the math for normal lines works. Have a look at this article - Converting lines from normal to slope intercept form it goes through the math.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With