本文介绍了在 C++ 中的 OpenCV 中旋转图像而不裁剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我想旋转图像,但我无法在不裁剪的情况下获得旋转的图像
I'd like to rotate an image, but I can't obtain the rotated image without cropping
我的原图:
现在我使用这个代码:
并获得以下图像:
但我想得到这个:
推荐答案
我的回答受到以下帖子/博客条目的启发:
My answer is inspired by the following posts / blog entries:
- 使用 cv 旋转 cv::Mat::warpAffine 偏移目标图像
- http://john.freml.in/opencv-rotation
主要思想:
- 通过向新图像中心添加平移来调整旋转矩阵
- 使用
cv::RotatedRect
尽可能依赖现有的opencv功能
- Adjusting the rotation matrix by adding a translation to the new image center
- Using
cv::RotatedRect
to rely on existing opencv functionality as much as possible
使用 opencv 3.4.1 测试的代码:
Code tested with opencv 3.4.1:
这篇关于在 C++ 中的 OpenCV 中旋转图像而不裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!