【问题标题】:transfer the co-ordinates error in function传递函数中的坐标误差
【发布时间】:2013-04-17 21:56:33
【问题描述】:

我正在尝试将点的坐标转换为新生成的系统坐标

原系统中的原点在左上角....

我写了以下函数来传递坐标
我正在使用从这个问题中得到的正式形式 pre_question 这个问题有 2 张照片显示了我的意思以及每个部分的标志

现在的问题是,我得到了 w 的负值! 谁能检查一下这个功能,让我知道问题出在哪里

谢谢

{

CvPoint transfer_coordinate (CvPoint pt1 , CvPoint pt2 , CvPoint pt3 , CvPoint pt4 , CvPoint origin , CvPoint current)
{
// pt1 , pt2 ==> points in line Z 
// pt3 , pt4 ==> points in line W 
double a1 , a2 , b1 , b2 , d1 , d2;

d1= sqrt(pow((pt1.x - pt2.x),2.0)+ pow((pt1.y - pt2.y),2.0)); 
d2= sqrt(pow((pt3.x - pt4.x),2.0)+ pow((pt3.y - pt4.y),2.0)); 

a1 =(pt1.y-pt2.y)/d1;
b1 =(pt2.x-pt1.x)/d1;

a2 =(pt3.y-pt4.y)/d2; 
b2 =(pt4.x-pt3.x)/d2; 

CvPoint new_point;
//z = -sqrt(a1^2+b1^2)*(a2*(x-x0)+b2*(y-y0))/(a2*b1-a1*b2)
//w =  sqrt(a2^2+b2^2)*(a1*(x-x0)+b1*(y-y0))/(a1*b2-a2*b1)
//z
new_point.x = -round(sqrt(pow(a1,2.0)+ pow(b1,2.0)) * (a2 * (current.x - origin.x) + b2 * (current.y - origin.y))/(a2 * b1 - a1 * b2));
// w
new_point.y = round(sqrt(pow(a2,2.0)+ pow(b2,2.0)) * (a1 * (current.x - origin.x) + b1 * (current.y - origin.y))/(a1 * b2 - a2 * b1)); 

CvPoint reverse_point; 
//x = x0 - b1*z/sqrt(a1^2+b1^2) + b2*w/sqrt(a2^2+b2^2)
//y = y0 + a1*z/sqrt(a1^2+b1^2) - a2*w/sqrt(a2^2+b2^2)
//x
reverse_point.x = round (origin.x - b1 * new_point.x / sqrt(pow(a1,2.0) + pow(b1,2.0)) + b2 * new_point.y /sqrt(pow(a2,2)+ pow(b2,2)));
//y
reverse_point.y = round (origin.y + a1 * new_point.x / sqrt(pow(a1,2.0) + pow(b1,2.0)) - a2 * new_point.y /sqrt(pow(a2,2)+ pow(b2,2)));

//printf("\n points in Z line (%d,%d),(%d,%d) , points in W line (%d,%d),(%d,%d) , origin (%d,%d)",pt1.x,pt1.y,pt2.x,pt2.y,pt3.x,pt3.y,pt4.x,pt4.y,origin.x,origin.y);
//printf("\n current point = (%d,%d) , new point = (%d,%d) , reverse point = (%d,%d)" , current.x,current.y,new_point.x,new_point.y,reverse_point.x,reverse_point.y);

return new_point ; 

}

}

【问题讨论】:

    标签: math opencv line coordinate-systems


    【解决方案1】:

    如果你的 W 轴对应 X 轴,那么仿射变换矩阵是 M = [R]*[T],其中 R 是 Phi 角的旋转矩阵,T 是 x0, y0 的平移矩阵

    R = Cos(phi) -Sin(phi) 0
        Sin(phi)  Cos(phi) 0
        0         0       1
    

    T = 1  0  0
        0  1  0
        dx dy 1
    

    你必须将这些矩阵相乘才能得到 M 矩阵并得到逆矩阵 MR = Inverse(M)。然后您可以使用 M 和 MR 将坐标从 XY 转换为 WZ 系统,反之亦然 [xnew, ynew, 1] = [xold, yold, 1] * [M]

    More information here

    【讨论】:

      猜你喜欢
      • 2017-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-10
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      相关资源
      最近更新 更多