Convert HoughLines to opencv

I am working on image processing using opencv and Eclipse.

vector<Vec2f> lines; HoughLines(dst, lines, 1, CV_PI/180, 100, 0, 0 ); for( size_t i = 0; i < lines.size(); i++ ) { float rho = lines[i][0], theta = lines[i][1]; Point pt1, pt2; double a = cos(theta), b = sin(theta); double x0 = a*rho, y0 = b*rho; pt1.x = cvRound(x0 + 1000*(-b)); pt1.y = cvRound(y0 + 1000*(a)); pt2.x = cvRound(x0 - 1000*(-b)); pt2.y = cvRound(y0 - 1000*(a)); line( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA); } 

Can anyone explain how exactly these points are defined by this code. We use

 y=(-cos(theta)/sin(theta))x + r/(sin(theta)) rho=xo*cos(theta) + yo*sin(theta) 

I can not understand why the multiplication of 1000 is performed in a line

 pt1.x = cvRound(x0 + 1000*(-b)); 

try to explain it in simple words. thanks in advance

+1
source share
3 answers

The question has already been answered. But since I spent the last fifteen minutes drawing this diagram, I could also publish it anyway. Maybe this helps:

enter image description here

So, you have a point p0 = (x0,y0) , which is on the line. Then you calculate the other two points on the line that are 1000 units from p0 in each direction.

+13
source

It seems that the code is trying to draw a string of parameters returned by the Hough Transform function. Multiplying by 1000 makes it so that your points move along the line (in opposite directions, so pt1 adds and pt2 subtracts) from the starting position to actually draw a line. Different values โ€‹โ€‹of this number should give you different lengths of line segments. If you're interested, try replacing the value of a variable (e.g. line_length ), and then change the value of that variable to see how it affects the look of your output.

+1
source

Here is a detailed explanation of 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 image to see it in full size)

enter image description here

In this case, d1 = d2 = 1000 .

+1
source

All Articles