opencv 仿射变换 计算旋转矩阵源码分析

在使用opencv进行仿射变换的时候,会先计算一个放射变换矩阵,获取放射变换矩阵的函数原型:


 

/* Computes rotation_matrix matrix */

CVAPI(CvMat*)  cv2DRotationMatrix( CvPoint2D32f center, double angle,

                                   double scale, CvMat* map_matrix );


这个函数的实现为:

 


 

CV_IMPL CvMat*

cv2DRotationMatrix( CvPoint2D32f center, double angle,

                    double scale, CvMat* matrix )

{

    cv::Mat M0 = cv::cvarrToMat(matrix), M = cv::getRotationMatrix2D(center, angle, scale);

    CV_Assert( M.size() == M.size() );

    M.convertTo(M0, M0.type());

    return matrix;

}


上面的函数中,主要的功能函数是: 

 


 

cv::Mat cv::getRotationMatrix2D( Point2f center, double angle, double scale )

{

    angle *= CV_PI/180;

    double alpha = cos(angle)*scale;

    double beta = sin(angle)*scale;



    Mat M(2, 3, CV_64F);

    double* m = (double*)M.data;



    m[0] = alpha;

    m[1] = beta;

    m[2] = (1-alpha)*center.x - beta*center.y;

    m[3] = -beta;

    m[4] = alpha;

    m[5] = beta*center.x + (1-alpha)*center.y;



    return M;

}


首先将角度转换为了弧度,然后计算旋转矩阵。

 

 

你可能感兴趣的:(opencv)