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

☆樱花仙子☆ 提交于 2019-12-23 10:07:53

问题


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,


回答1:


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.



来源:https://stackoverflow.com/questions/5308647/how-to-convert-coordinates-back-to-image-x-y-from-hough-transformation-rho-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!