Have created a c++ implementation of the Hough transform for detecting lines in images. Found lines are represented using rho, theta, as described on wikipedia:
‘The parameter r represents the distance between the line and the origin, while θ is the angle of the vector from the origin to this closest point ‘
How can i find the intersection point in x, y space for two lines described using r, θ?
For reference here are my current functions for converting in and out of hough space:
//get 'r' (length of a line from pole (corner, 0,0, distance from center) perpendicular to a line intersecting point x,y at a given angle) given the point and the angle (in radians) inline float point2Hough(int x, int y, float theta) { return((((float)x)*cosf(theta))+((float)y)*sinf(theta)); } //get point y for a line at angle theta with a distance from the pole of r intersecting x? bad explanation! >_< inline float hough2Point(int x, int r, float theta) { float y; if(theta!=0) { y=(-cosf(theta)/sinf(theta))*x+((float)r/sinf(theta)); } else { y=(float)r; //wth theta may == 0?! } return(y); }
sorry in advance if this is something obvious..
Looking at the Wikipedia page, I see that the equation of a straight line corresponding to a given given r, θ pair is
Thus, if I understand, given two pairs r1, θ1 and r2, θ2, to find the intersection you must solve for the unknowns x,y the following linear 2×2 system:
that is AX = b, where