Android OpenCV 旋转图像
2016-12-28 11:45
447 查看
使用opencv的摄像头预览图像是逆时针旋转90度的。
c++的方法多一点,我就想java也有直接的办法。参考API后看到这样一个方法,在Imgproc类下。
API说明:
我在预览里添加转换函数:
c++的方法多一点,我就想java也有直接的办法。参考API后看到这样一个方法,在Imgproc类下。
API说明:
getRotationMatrix2D public static Mat getRotationMatrix2D(Point center, double angle, double scale) Calculates an affine matrix of 2D rotation. The function calculates the following matrix: alpha beta(1- alpha) * center.x - beta * center.y - beta alpha beta * center.x + (1- alpha) * center.y where alpha = scale * cos angle, beta = scale * sin angle The transformation maps the rotation center to itself. If this is not the target, adjust the shift. Parameters: center - Center of the rotation in the source image. angle - Rotation angle in degrees. Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner). scale - Isotropic scale factor.
warpAffine public static void warpAffine(Mat src, Mat dst, Mat M, Size dsize) Applies an affine transformation to an image. The function warpAffine transforms the source image using the specified matrix: dst(x,y) = src(M _11 x + M _12 y + M _13, M _21 x + M _22 y + M _23) when the flag WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with "invertAffineTransform" and then put in the formula above instead of M. The function cannot operate in-place. Note: cvGetQuadrangleSubPix is similar to cvWarpAffine, but the outliers are extrapolated using replication border mode. Parameters: src - input image. dst - output image that has the size dsize and the same type as src. M - 2x 3 transformation matrix. dsize - size of the output image.
我在预览里添加转换函数:
@Override public Mat onCameraFrame(CvCameraViewFrame inputFrame) { // TODO Auto-generated method stub Mat dst = new Mat(); Mat gray = inputFrame.gray(); Mat rotateMat = Imgproc.getRotationMatrix2D(new Point(gray.rows()/2,gray.cols()/2), 90, 1); Imgproc.warpAffine(gray, dst, rotateMat, dst.size()); return dst; }图像顺时针旋转90度
相关文章推荐
- OpenCV4Android中图像预览旋转90度的问题
- Android Jni 利用OpenCV 实现图像任意角度旋转
- opencv 任意角度旋转图像
- android-->图像旋转遇到的问题
- Android-图像识别项目OpenCV(1):技术选型以及NDK搭建
- Android-图像识别项目OpenCV(4):开发思路以及问题
- Android-图像识别项目OpenCV(3):程序目标以及单独发布
- OPENCV 中的图像旋转与缩放
- OpenCV 下的图像任意角度的旋转
- android.graphics.Camera实现图像的旋转、缩放,配合Matrix实现图像的倾斜
- Android 图像系列: 旋转Bitmap
- Android-图像识别项目OpenCV(4):开发思路以及问题
- [Android]android.graphics.Camera实现图像的旋转、缩放,配合Matrix实现图像的倾斜
- OpenCv调整图像大小及仿射变换(旋转)
- opencv图像旋转90度
- android.graphics.Camera实现图像的旋转、缩放,配合Matrix...
- android:动态缩放和旋转图像
- openCv 图像顺时针、逆时针旋转
- opencv实现图像旋转
- Android-图像识别项目OpenCV(2):运行官方例子中的脸部识别程序