Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert coordinates back to image (x,y) from hough transformation (rho, theta)?

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,

like image 369
Haoest Avatar asked Mar 15 '11 07:03

Haoest


1 Answers

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.

like image 166
Utkarsh Sinha Avatar answered Sep 29 '22 20:09

Utkarsh Sinha