HoughLines transform in opencv

混江龙づ霸主 提交于 2019-11-30 10:27:22

The question has already been answered. But since I spend the last fifteen minutes drawing this diagram I might as well post it anyway. Maybe it helps:

So what you have is a Point p0 = (x0,y0) which is on the line. You then compute two other points on the line which are 1000 units away from p0 in each direction.

Here's a detailed explanation for this piece of code:

 pt1.x = cvRound(x0 + 1000*(-b));  
 pt1.y = cvRound(y0 + 1000*(a));  
 pt2.x = cvRound(x0 - 1000*(-b));  
 pt2.y = cvRound(y0 - 1000*(a));

(click on the picture to see it in full size)

In this case d1 = d2 = 1000.

The code appears to be trying to draw a line from the parameters returned by the Hough Transform function. The multiplication by 1000 makes it so that your points are moved along the line (in opposite directions, which is why pt1 adds and pt2 subtracts) from the starting position in order to actually draw the line. Different values of that number should give you different line segment lengths. If you are curious, try replacing the value with a variable (like line_length) and then vary the value of that variable to see how it affects the appearance of your output.

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