坐标转换案例
在C++中利用Eigen库对图像中的点进行旋转平移,以达到对图像的基本操作。
#include <iostream>
#include <Eigen/Dense>
#include <math.h>
#include <opencv/cv.hpp>
using namespace std;
# define deg2rad M_PI/180
Eigen::Matrix4f createTransformMatrix(Eigen::Vector3f theta, Eigen::Vector3f pose) {
/* 介绍:根据旋转角度和平移向量,算出4*4的旋转平移矩阵
* Eigen::Vector3d theta:旋转角度
* Eigen::Vector3d pose:平移向量
* */
//平移矩阵
Eigen::Matrix4f Pan_Matrix;
Pan_Matrix <<
1, 0, 0, pose[0],
0, 1, 0, pose[1],
0, 0, 1, pose[2],
0, 0, 0, 1;
//绕x旋转
Eigen::Matrix3f x_rotate;
x_rotate << 1, 0, 0,
0, cos(deg2rad * theta[0]), -sin(deg2rad * theta[0]),
0, sin(deg2rad * theta[0]), cos(deg2rad * theta[0]);
//绕y旋转
Eigen::Matrix3f y_rotate;
y_rotate << cos(deg2rad * theta[1]), 0, sin(deg2rad * theta[1]),
0, 1, 0,