画像内の線を検出するためのハフ変換のc++実装を作成しました。見つかった行は、ウィキペディアで説明されているように、rho、thetaを使用して表されます。
「パラメータrは線と原点の間の距離を表し、θは原点からこの最も近い点までのベクトルの角度です。」
r、θを使用して記述された2本の線のx、y空間で交点を見つけるにはどうすればよいですか?
参考までに、ハフ空間に変換したりハフ空間から変換したりするための現在の関数は次のとおりです。
//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);
}
これが明らかな場合は、事前に申し訳ありません。