将这一段代码的warpAffine转换成transform实现 Mat RotateMat = getRotationMatrix2D(m_pdCenter, -m_dAngle, 1); warpAffine(RoiMat, RoiMat, RotateMat, RoiMat.size(), WARP_INVERSE_MAP);
时间: 2024-02-27 10:57:29 浏览: 70
AffineTransform_仿射变换_AffineTransform_源码
可以使用cv::transform函数来实现:
1. 定义一个旋转矩阵RotateMat:
```
cv::Mat RotateMat = cv::getRotationMatrix2D(m_pdCenter, -m_dAngle, 1);
```
2. 将旋转矩阵展开成一个3x3的矩阵,第三行为[0,0,1]:
```
cv::Mat affineMat = cv::Mat::zeros(3, 3, RotateMat.type());
affineMat.at<double>(0, 0) = RotateMat.at<double>(0, 0);
affineMat.at<double>(0, 1) = RotateMat.at<double>(0, 1);
affineMat.at<double>(0, 2) = (1 - RotateMat.at<double>(0, 0)) * m_pdCenter.x - RotateMat.at<double>(0, 1) * m_pdCenter.y;
affineMat.at<double>(1, 0) = RotateMat.at<double>(1, 0);
affineMat.at<double>(1, 1) = RotateMat.at<double>(1, 1);
affineMat.at<double>(1, 2) = RotateMat.at<double>(1, 0) * m_pdCenter.y + (1 - RotateMat.at<double>(1, 1)) * m_pdCenter.x;
affineMat.at<double>(2, 2) = 1;
```
3. 使用cv::transform函数进行仿射变换:
```
cv::Mat result;
cv::transform(RoiMat, result, affineMat);
```
其中,RoiMat是原始图像,result是仿射变换后的结果。
阅读全文