[英]How rotate a Landscape Image to Portrait in Android OpenCV 3
This code rotate a image from Landscape to Portrait, but I can't do it in Android. 这段代码将图像从横向旋转到纵向,但是在Android中无法做到。 What is the equivalent code? 等效代码是什么?
import cv2
import numpy
img = cv2.imread('original.png')
h, w = img.shape[:2]
img2 = numpy.zeros((w, h, 3), numpy.uint8)
cv2.transpose(img, img2)
cv2.flip(img2, 1, img2)
cv2.imwrite('rotate.png', img2)
I assume you have your image as OpenCV Mat in Android (you can load an image by using the Imgcodecs.imread()
method). 我假设您将图像作为Android中的OpenCV Mat(您可以使用Imgcodecs.imread()
方法加载图像)。
Then you can just do it like this: 然后,您可以像这样:
Mat src = Imgcodecs.imread("path/to/file"); // initialize this with your image from file
Core.flip(src.t(), src, 1); // this will rotate the image 90° clockwise
Core.flip(src.t(), src, 0); // this will rotate the image 90° counter-clockwise
After that, use Imgcodecs.imwrite()
to save the image. 之后,使用Imgcodecs.imwrite()
保存图像。 Make sure you add the permissions to your Manifest: 确保将权限添加到清单中:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
[SOLVED]... [解决了]...
Get a landscape, like (W)800 x (H) 600, and outpout a (H)800 x (W)600. 获得风景(W)800 x(H)600,然后输出(H)800 x(W)600。 :) :)
Core.transpose(mRgba, mRgbaT); Imgproc.resize(mRgbaT, mRgbaF, mRgbaT.size(), 0, 0, 0); Core.flip(mRgbaF, mRgbaF, 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.