【问题标题】:Intersection of two lines defined in (rho/theta ) parameterization(rho/theta) 参数化中定义的两条线的交点
【发布时间】:2010-09-27 20:42:36
【问题描述】:

已经创建了 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);
}

如果这是显而易见的事情,请提前抱歉..

【问题讨论】:

    标签: c math image-processing geometry


    【解决方案1】:

    查看Wikipedia page,我看到给定给定r,θ对对应的直线方程是

    r = x cosθ + y sinθ 

    因此,如果我理解的话,给定两对 r1, θ1 和 r2, θ2,要找到交点,您必须通过以下线性 2x2 系统求解未知数 x,y:

    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| |是|
    

    【讨论】:

    • 小心,这个解决方案是不完整的。对于平行或重合的线没有解决方案。 @eirsu(下)的答案效果更好。
    【解决方案2】:

    以前从未遇到过矩阵数学,因此进行了一些研究和实验来制定 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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      相关资源
      最近更新 更多