(ρ/θ)参数化中定义的两条直线的交点 已经创建了一个C++实现Hough变换用于检测图像中的线。如维基百科所述,找到的线用ρ、θ表示:

(ρ/θ)参数化中定义的两条直线的交点 已经创建了一个C++实现Hough变换用于检测图像中的线。如维基百科所述,找到的线用ρ、θ表示:,c,math,image-processing,geometry,C,Math,Image Processing,Geometry,参数r表示直线和原点之间的距离,而θ表示向量从原点到最近点的角度 如何在x,y空间中找到用r,θ描述的两条直线的交点 以下是我当前在hough空间内外转换的函数,仅供参考: //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

参数r表示直线和原点之间的距离,而θ表示向量从原点到最近点的角度

如何在x,y空间中找到用r,θ描述的两条直线的交点

以下是我当前在hough空间内外转换的函数,仅供参考:

//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);
}
//获取与给定点和角度(以弧度为单位)相交点x、y的直线垂直于极点(角,0,0,距中心的距离)的“r”(直线长度)
内联浮点2hough(整数x,整数y,浮点θ){
返回(((浮点)x)*cosf(θ))+((浮点)y)*sinf(θ));
}
//得到一条线的点y,该线的角度为θ,距离r的极点与x相交?糟糕的解释!>_<
内联浮点hough2Point(整数x,整数r,浮点θ){
浮动y;
如果(θ!=0){
y=(-cosf(θ)/sinf(θ))*x+((浮点)r/sinf(θ));
}否则{
y=(float)r;//θ可以=0吗?!
}
返回(y);
}
如果这是显而易见的话,请先道歉。

看看,我看到,与给定r,θ对相对应的直线方程是

r = x cosθ + y sinθ r=x cosθ+y sinθ 因此,如果我理解,给定两对r1,θ1和r2,θ2,为了找到交集,你必须为未知量x,y求解以下线性2x2系统:

x cos θ1 + y sin θ1 = r1 x cos θ2 + y sin θ2 = r2 x cosθ1+y sinθ1=r1 x cosθ2+y sinθ2=r2 也就是AX=b,其中

A = [cos θ1 sin θ1] b = |r1| X = |x| [cos θ2 sin θ2] |r2| |y| A=[cosθ1 sinθ1]b=|r1 | X=|X| [cosθ2sinθ2]| r2 | y|
我以前从未遇到过矩阵数学,所以花了一些研究和实验来找出Fredrico答案的过程。谢谢,我还是需要学习矩阵^^

函数查找两条参数化线相交的位置:

//Find point (x,y) where two parameterized lines intersect :p Returns 0 if lines are parallel 
int parametricIntersect(float r1, float t1, float r2, float t2, int *x, int *y) {
    float ct1=cosf(t1);     //matrix element a
    float st1=sinf(t1);     //b
    float ct2=cosf(t2);     //c
    float st2=sinf(t2);     //d
    float d=ct1*st2-st1*ct2;        //determinative (rearranged matrix for inverse)
    if(d!=0.0f) {   
            *x=(int)((st2*r1-st1*r2)/d);
            *y=(int)((-ct2*r1+ct1*r2)/d);
            return(1);
    } else { //lines are parallel and will NEVER intersect!
            return(0);
    }
}

小心,这个解决方案是不完整的。对于平行或重合的直线,没有解决方案。@eirsu(以下)的答案更有效。