本文介绍了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:

这篇关于OpenCV:如何旋转 IplImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 14:45