The equation of the line in Cartesian coordinates:
y = k * x + b
Two lines y = k1 * x + b1, y = k2 * x + b2 are parallel if k1 = k2.
So, you need to calculate the coefficient k for each detected line.
To uniquely identify the equation of a line, you need to know the coordinates of two points that belong to the line.
After finding the lines with HoughLines (C ++):
vector<Vec2f> lines; HoughLines(dst, lines, 1, CV_PI/180, 100, 0, 0 );
you have vector lines in which the parameters (r, theta) of the detected lines are stored in polar coordinates. You need to transfer them to Cartesian coordinates:
Here is an example in C ++:
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));
Having received these two points of the line, you can calculate its equation.
Ann orlova
source share