OpenCV:如何旋转IplImage? [英] OpenCV: how to rotate IplImage?
本文介绍了OpenCV:如何旋转IplImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将图像旋转很小的角度,例如1-5度. OpenCV 是否提供简单的方法?通过阅读文档,我可以假定应该涉及到 getAffineTransform(),但是没有直接的示例来做类似的事情:
I need to rotate an image by very small angle, like 1-5 degrees. Does OpenCV provide simple way of doing that? From reading docs i can assume that getAffineTransform() should be involved, but there is no direct example of doing something like:
IplImage *rotateImage( IplImage *source, double angle);
推荐答案
如果您使用OpenCV> 2.0,那么就像
If you use OpenCV > 2.0 it is as easy as
using namespace cv;
Mat rotateImage(const Mat& source, double angle)
{
Point2f src_center(source.cols/2.0F, source.rows/2.0F);
Mat rot_mat = getRotationMatrix2D(src_center, angle, 1.0);
Mat dst;
warpAffine(source, dst, rot_mat, source.size());
return dst;
}
注意:角度以度为单位,而不是弧度.
Note: angle is in degrees, not radians.
有关更多详细信息,请参见C ++接口文档,并根据需要进行调整:
See the C++ interface documentation for more details and adapt as you need:
- getRotationMatrix
- warpAffine
这篇关于OpenCV:如何旋转IplImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文