opencv中图像旋转比较快得方法
时间: 2023-10-09 11:05:22 浏览: 93
在CV 中,可以使用 `cv::warpAffine` 函数来快速旋转图像。该函数可以通过提供旋转矩阵来执行图像旋转。
下面是一个示例代码,演示如何使用 `cv::warpAffine` 函数将图像旋转 45 度:
```c++
#include <opencv2/opencv.hpp>
int main()
{
cv::Mat image = cv::imread("image.jpg");
double angle = 45; // 旋转角度
cv::Point2f center(image.cols / 2, image.rows / 2); // 旋转中心点
// 计算旋转矩阵
cv::Mat rotation = cv::getRotationMatrix2D(center, angle, 1);
// 执行图像旋转
cv::Mat rotatedImage;
cv::warpAffine(image, rotatedImage, rotation, image.size());
cv::imshow("Original Image", image);
cv::imshow("Rotated Image", rotatedImage);
cv::waitKey(0);
return 0;
}
```
在这个示例中,我们首先读取了一个图像,然后指定旋转角度和中心点。接下来,我们使用 `cv::getRotationMatrix2D` 函数计算旋转矩阵,最后使用 `cv::warpAffine` 函数旋转图像并显示结果。
这种方法比较快速,并且适用于任意角度的图像旋转。
阅读全文
相关推荐













