如何找到两个棋盘平面之间的角度?

时间:2018-09-21 10:01:54

标签: c++ opencv perspectivecamera

我有两个通过solvePnp获得的棋盘姿势:

Mat rotationVector1, translationVector1;
solvePnP(chess1WorldPoints, chess1ImagePoints, intrinsicMatrix, distortCoefficients, rotationVector1, translationVector1);

Mat rotationVector2, translationVector2;
solvePnP(chess2WorldPoints, chess2ImagePoints, intrinsicMatrix, distortCoefficients, rotationVector2, translationVector2);

如何检查姿势平面是否平行或在这些平面之间找到​​角度?

更多信息

我尝试获取欧拉角并计算每个alpha,beta和gamma之间的差,但这只能告诉我我认为的每个轴的相对旋转:

Vec3d eulerAnglesPose1; 
Mat rotationMatrix1;
Rodrigues(rotationVector1, rotationMatrix1);
getEulerAngles(rotationMatrix1, eulerAngles1);

Vec3d eulerAnglesPose2;
Mat rotationMatrix2;
Rodrigues(rotationVector2, rotationMatrix2);
getEulerAngles(rotationMatrix2, eulerAngles2);

我使用了this page中的getEulerAngles实现:

void getEulerAngles(Mat &rotCamerMatrix, Vec3d &eulerAngles) 
{
    Mat cameraMatrix, rotMatrix, transVect, rotMatrixX, rotMatrixY, rotMatrixZ;
    double* _r = rotCamerMatrix.ptr<double>();
    double projMatrix[12] = 
    { 
     _r[0],_r[1],_r[2],0,
     _r[3],_r[4],_r[5],0,
     _r[6],_r[7],_r[8],0 
    };

    decomposeProjectionMatrix(Mat(3, 4, CV_64FC1, projMatrix), cameraMatrix, rotMatrix, transVect, rotMatrixX, rotMatrixY, rotMatrixZ, eulerAngles);
}

修改

在我的情况下,旋转-平移对(R,T)给出了相机在(0,0,0)的坐标系(相机坐标系)与其中(0,0 ,0)是我在solvePnp(世界坐标系)的前两个参数中定义的。所以我有两个相对于同一相机坐标系的世界坐标系。 如果我可以从协调转换。系统2进行协调。系统1我可以对每个平面使用Z = 0平面来查找法线并解决我的问题。

我认为例如从协调转换。系统2到相机系统的操作应类似于another hdf file

Rinv = R' (just the transpose as it's a rotation matrix)
Tinv = -Rinv * T (T is 3x1 column vector)

则如果Pw = [X Y Z]是世界坐标系中的一点。系统2我可以通过以下方式获得其相机系统坐标:

Pc = [ Rinv Tinv] * [X Y Z 1] transposed.
Pc looks like [a b c d]

再次遵循相同的逻辑,我可以获得相对于坐标的Pc坐标。系统1:

Pw1 = [ R1 T1] * Pc

我应该规范化Pc还是仅仅规范化Pw1?

1 个答案:

答案 0 :(得分:0)

在此OpenCV Demo中,我找到了如何在坐标系之间平移点。

“演示3:从摄影机位移开始的同形像”(从标题右边一直到代码的第一行)的解释说明了如何使用矩阵乘法在坐标系之间进行转换。我只需要将其应用于我的情况(我有 C M O1 C M O2 找到 O1 M O2 )。

这样,我可以在同一坐标系中获得两架飞机。系统,获取它们的法线并找到它们之间的角度。

它也有助于认识到外部矩阵[RT]转换了世界坐标的3D点。相机坐标系。系统(摄像头位于(0,0,0)),而不是相反。

相关问题