void Extract1DEdge::GetProfieMat() { if (m_mInputMat.empty()) { return; } if (m_mInputMat.channels() > 1) { cvtColor(m_mInputMat, m_mInputMat, COLOR_BGR2GRAY); } Mat RotateMat = getRotationMatrix2D(m_pdCenter, -m_dAngle, 1); warpAffine(m_mInputMat, m_mInputMat, 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(m_mInputMat, m_mInputMat, M, Size2d(m_dLength, m_dHeight), WARP_INVERSE_MAP); }如何保持两个warpAffine效果不变的情况下加速这段代码给个例程
时间: 2024-02-17 13:05:22 浏览: 23
可以考虑将两次 warpAffine 合并成一次变换,从而避免重复计算。具体来说,可以将两个变换矩阵相乘,然后一次性应用到输入图像上。修改后的代码如下所示:
```
void Extract1DEdge::GetProfieMat() {
if (m_mInputMat.empty()) {
return;
}
if (m_mInputMat.channels() > 1) {
cvtColor(m_mInputMat, m_mInputMat, COLOR_BGR2GRAY);
}
Mat RotateMat = getRotationMatrix2D(m_pdCenter, -m_dAngle, 1);
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);
Mat combinedMat = M * RotateMat;
warpAffine(m_mInputMat, m_mInputMat, combinedMat, Size2d(m_dLength, m_dHeight), WARP_INVERSE_MAP);
}
```
其中,变换矩阵 combinedMat 为 M 和 RotateMat 的乘积。通过这种方式,可以避免重复计算,提高代码运行效率。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)