将这一段代码的warpAffine转换成transform实现 Mat RotateMat = getRotationMatrix2D(m_pdCenter, -m_dAngle, 1); warpAffine(RoiMat, RoiMat, RotateMat, m_mInputMat.size(), WARP_INVERSE_MAP); Mat newCenter = RotateMat * (Mat_<double>(3, 1) << m_pdCenter.x, m_pdCenter.y, 1); double x = newCenter.at<double>(0, 0); double y = newCenter.at<double>(1, 0); Mat M = (Mat_<double>(2, 3) << 1, 0, x - m_dLength * 0.5, 0, 1, y - m_dHeight * 0.5); warpAffine(RoiMat, m_mInputMat, M, Size2d(m_dLength, m_dHeight), WARP_INVERSE_MAP);
时间: 2024-02-27 16:57:44 浏览: 269
AffineTransform_仿射变换_AffineTransform_源码
以下是将该段代码的warpAffine转换成transform实现的代码:
```
Mat RotateMat = getRotationMatrix2D(m_pdCenter, -m_dAngle, 1);
Mat invRotateMat;
invertAffineTransform(RotateMat, invRotateMat);
Mat newCenter = invRotateMat * (Mat_<double>(3, 1) << m_pdCenter.x, m_pdCenter.y, 1);
double x = newCenter.at<double>(0, 0);
double y = newCenter.at<double>(1, 0);
Mat M = (Mat_<double>(2, 3) << cos(m_dAngle), sin(m_dAngle), x - m_dLength * 0.5, -sin(m_dAngle), cos(m_dAngle), y - m_dHeight * 0.5);
warpAffine(RoiMat, m_mInputMat, M, Size2d(m_dLength, m_dHeight), INTER_LINEAR, BORDER_CONSTANT, Scalar(0, 0, 0));
```
其中,invertAffineTransform函数用于求解仿射矩阵的逆矩阵,将旋转中心坐标进行反向变换,从而得到旋转后的中心坐标。M矩阵的第一行是x轴方向的变换,第二行是y轴方向的变换。最后一个参数Scalar(0,0,0)是指边界填充的颜色,可根据需要进行修改。
阅读全文