使用opencv的摄像头预览图像是逆时针旋转90度的。

c++的方法多一点,我就想java也有直接的办法。参考API后看到这样一个方法,在Imgproc类下。

API说明:

getRotationMatrix2Dpublic 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.ywherealpha = scale * cos angle, beta = scale * sin angleThe 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.

warpAffinepublic 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.

我在预览里添加转换函数:
@Overridepublic 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度


更多相关文章

  1. 12、android socket使用demo:网络聊天
  2. 如何在Android平台上使用JS直接调用Java方法
  3. android canvas与图层的关系
  4. Android(安卓)RectF转换为Rect的方法
  5. android eclipse中导入framework.jar以及使用其隐藏类的方法
  6. Android中ImageButton自定义按钮的按下效果的代码实现方法,附网上
  7. Android(安卓)SQLite3 数据库操作
  8. android Tabhost中,控制activity的生命周期
  9. Android中文API(133) —— LocationListener

随机推荐

  1. Android动态加载Dex技术基础
  2. Android(安卓)Studio1.5使用和学习记录
  3. 【译】使用Kotlin从零开始写一个现代Andr
  4. Android之Goldfish
  5. android studio 设置编译apk的名称以及配
  6. Android市场官方的统计信息
  7. Android 之 Looper Handler Message 之间
  8. 《Android经验分享》周刊第9期
  9. 【android】Android Wi-Fi Direct 开发指
  10. Android开发艺术探索—— 第十一章Androi