//#include "header.h"
#include "opencv2/core.hpp"
#include <opencv2/core/utility.hpp>
#include "opencv2/imgproc.hpp"
#include "opencv2/calib3d.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include<iostream>
#include <math.h>
using namespace cv;
using namespace std;
#define PI acos(-1)
/*测试opencv旋转角和旋转矩阵互转的函数
函数定义:
void cv::Rodrigues (
InputArray src,
OutputArray dst,
OutputArray jacobian = noArray()
)
参数都是opencv里最公共的数组数据类型,意味着可以传入任何的数组类型,如vector,scalar,Matx,Mat
注意:旋转向量的单位是幅度
*/
float unit = 180/PI;//1幅度=180/PI角度
//Matx是固定维度的小Mat,如Matx31f是3x1,float类型的Mat,通过Mat()可以直接转化成Mat
Matx31f to_Rvec(Matx33f Rmatrix){
Matx31f dst;
cv::Rodrigues(Rmatrix,dst,noArray());
return dst;
}
Matx33f to_Rmatrix(Matx31f Rvec){
Matx33f dst;
cv::Rodrigues(Rvec,dst,noArray());
return dst;
}
int main(){
Matx31f Rvec = Matx31f(0,1.57,0);//单位是幅度,角度是(0,90左右,0)
cout << "转换成旋转矩阵后"<<to_Rmatrix(Rvec)<<endl;
Matx33f Rmatrix = Matx33f(1,2,3,4,5,6,7,8,9);
cout<<"转换成角度后"<<(1/unit)*to_Rvec(Rmatrix)<<endl;
}