使用OpenCv函数cvPosit的旋转角度矩阵

使用OpenCv函数cvPosit的旋转角度矩阵,opencv,rotation,estimation,angle,Opencv,Rotation,Estimation,Angle,我在做一个3D姿势估计系统。我使用OpenCVs函数cvPosit来计算旋转矩阵和平移向量 我还需要旋转矩阵的角度,但似乎没有算法在工作 函数cv::RQDecomp3x3(),这是“在opencv中:如何从正定旋转矩阵获得偏航、横滚、俯仰”主题的答案,无法工作,因为该函数需要投影矩阵的3x3矩阵 此外,我尝试使用下面链接中的算法,但没有任何效果 visionopen.com/cv/vosm/doc/html/recognitionalgs_8cpp_source.html stackoverf

我在做一个3D姿势估计系统。我使用OpenCVs函数cvPosit来计算旋转矩阵和平移向量

我还需要旋转矩阵的角度,但似乎没有算法在工作

函数cv::RQDecomp3x3(),这是“在opencv中:如何从正定旋转矩阵获得偏航、横滚、俯仰”主题的答案,无法工作,因为该函数需要投影矩阵的3x3矩阵

此外,我尝试使用下面链接中的算法,但没有任何效果

visionopen.com/cv/vosm/doc/html/recognitionalgs_8cpp_source.html

stackoverflow.com/questions/16266740/in-opencv-how-to-get-yaw-roll-pitch-from-posit-rotation-matrix

quad08pyro.groups.et.byu.net/vision.htm

stackoverflow.com/questions/13565625/opencv-c-posit-why-are-my-values-always-nan-with-small-focal-length

www.c-plusplus.de/forum/308773-full

我使用了最常见的Posite教程和Blender的一个示例,因此我可以渲染一幅图像来检索图像点并知道确切的角度。Blender中对象的Z轴旋转了10度——由于Blender和OpenCV之间的轴发生了变化,我检查了所有3个轴的所有角度

double focalLength = 700.0;
CvPOSITObject* positObject;
std::vector<CvPoint3D32f> modelPoints;
modelPoints.push_back(cvPoint3D32f(0.0f, 0.0f, 0.0f));  
modelPoints.push_back(cvPoint3D32f(CUBE_SIZE, 0.0f, 0.0f));
modelPoints.push_back(cvPoint3D32f(0.0f, CUBE_SIZE, 0.0f));
modelPoints.push_back(cvPoint3D32f(0.0f, 0.0f, CUBE_SIZE)); 

std::vector<CvPoint2D32f> imagePoints;
imagePoints.push_back( cvPoint2D32f( 157,372) );
imagePoints.push_back( cvPoint2D32f(423,386 ));
imagePoints.push_back( cvPoint2D32f( 157,108 ));
imagePoints.push_back( cvPoint2D32f(250,337));

// Moving the points to the image center as described in the tutorial
for (int i = 0; i < imagePoints.size();i++) {
    imagePoints[i] = cvPoint2D32f(imagePoints[i].x -320, 240 - imagePoints[i].y);
}

CvVect32f translation_vector = new float[3];    
CvTermCriteria criteria = cvTermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER,iterations, 0.1f);
positObject = cvCreatePOSITObject( &modelPoints[0], static_cast<int>(modelPoints.size()));
CvMatr32f rotation_matrix = new float[9];   
cvPOSIT( positObject, &imagePoints[0], focalLength, criteria, rotation_matrix, translation_vector );

algorithms to get angles...
double focalLength=700.0;
CvPOSITObject*positObject;
向量模型点;
模型点。推回(cvPoint3D32f(0.0f,0.0f,0.0f));
模型点。推回(cvPoint3D32f(立方体大小,0.0f,0.0f));
模型点。推回(cvPoint3D32f(0.0f,立方体大小,0.0f));
模型点。推回(cvPoint3D32f(0.0f,0.0f,立方体大小));
std::向量图像点;
imagePoints.push_back(cvPoint2D32f(157372));
imagePoints.推回(cvPoint2D32f(423386));
imagePoints.推回(cvPoint2D32f(157108));
imagePoints.push_back(cvPoint2D32f(250337));
//将点移动到图像中心,如教程中所述
对于(int i=0;i
我已经尝试从弧度到度和顺时针方向计算结果,但使用OpenCV中cvPosit的旋转矩阵已经得到了不好的结果。我还更改了矩阵格式以检查错误的格式

我使用了简单的旋转矩阵——就像只做x轴、y轴和z轴的旋转一样,并且一些算法有效。cvPosit的旋转矩阵不适用于该算法


我感谢大家的支持

我使用LGPL aforge.net框架中的ExtractYawPitchRoll函数中的代码解决了这个问题,该函数与OpenCVs Posite中的rotationmatrix一起工作。如果您不必使用POSIT的OpenCVs实现,那么可以使用forge.net的实现。这是获取旋转矩阵角度的完整代码:float偏航=(float)atan2f(旋转矩阵[2],旋转矩阵[8]);浮动节距=(浮动)asin(-rotation_矩阵[5]);浮动辊=(浮动)atan2f(旋转矩阵[3],旋转矩阵[4]);用弧度*计算角度(浮动)(180.0/CV_PI);