I have a vector of lines created by calling the hough to opencv transform function, and you need to convert them back to image coordinates. I found this sample code from the official Opencv documentation, but I don't get it. Can anyone explain please?
for( size_t i = 0; i < lines->size(); i++ )
{
float rho = lines->at(i)[0];
float theta = lines->at(i)[1];
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 makes 1000 of this line?
pt1(cvRound(x0 + 1000*(-b)), cvRound(y0 + 1000*(a)))
Also, why does pt2 have negative y cords? For example, if my first line is (0,0) in the format (rho, theta), pt2 will be (0, -1000).
Thank,
source
share