将图像旋转90、180或270度 [英] Rotate image by 90, 180 or 270 degrees

查看:509
本文介绍了将图像旋转90、180或270度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将图像旋转90、180或270度.在OpenCV4Android中,我可以使用:

I need to rotate an image by either 90, 180 or 270 degrees. In OpenCV4Android I can use:

Imgproc.getRotationMatrix2D(new Point(center, center), degrees, 1);
Imgproc.warpAffine(src, dst, rotationMatrix, dst.size());

但是,这是我的图像处理算法中的一个巨大瓶颈.当然,简单的旋转90度比warpAffine的最普通情况要简单得多,并且可以更有效地完成旋转.例如,对于180度,我可以使用:

However, this is a huge bottleneck in my image processing algorithm. Of course, a simple rotation by a multiple of 90 degrees is much simpler than the most general case of warpAffine, and can be done much more efficiently. For 180 degrees, for instance, I could use:

Core.flip(src, dst, -1);

其中-1表示围绕水平和垂直轴翻转.我可以使用90或270度的旋转进行类似的优化吗?

where -1 means to flip about both horizontal and vertical axes. Is there a similar optimization I could use for 90 or 270 degree rotations?

推荐答案

这是您在Google上搜索到的第一个结果,但这些解决方案都无法真正回答问题,或者是正确的还是简洁的.

This is the first result when you Google it and none of these solutions really answer the question or is correct or succinct.

Core.rotate(Mat src, Mat dst, Core.ROTATE_90_CLOCKWISE); //ROTATE_180 or ROTATE_90_COUNTERCLOCKWISE

这篇关于将图像旋转90、180或270度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆