为检测图像中的线条创建了 Hough 变换的 c++ 实现。找到的行使用 rho、theta 表示,如 wikipedia 上所述:
“参数r代表直线到原点的距离,而θ是向量从原点到这个最近点的夹角”
如何在 x, y 空间中找到使用 r, θ 描述的两条线的交点?
以下是我当前用于转换进出霍夫空间的函数供参考:
//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);
}
如果这是显而易见的事情,请提前抱歉..