使用 OpenCV 将图像旋转 90 度的最简单方法?

2021-12-10 00:00:00 opencv image rotation c++

将 IplImage/cv::Mat 旋转 90 度的最佳方法是什么(在 c/c++ 中)?我认为一定有比使用矩阵转换它更好的东西,但我似乎在 API 和在线中找不到其他任何东西.

What is the best way (in c/c++) to rotate an IplImage/cv::Mat by 90 degrees? I would assume that there must be something better than transforming it using a matrix, but I can't seem to find anything other than that in the API and online.

推荐答案

从 OpenCV3.2 开始,生活变得更简单了,您现在可以在一行代码中旋转图像:

As of OpenCV3.2, life just got a bit easier, you can now rotate an image in a single line of code:

cv::rotate(image, image, cv::ROTATE_90_CLOCKWISE);

对于方向,您可以选择以下任何一项:

For the direction you can choose any of the following:

ROTATE_90_CLOCKWISE
ROTATE_180
ROTATE_90_COUNTERCLOCKWISE

相关文章