关于 Android opencv 屏幕方向的bug

来源:互联网 发布:长沙网络棋牌软件开发 编辑:程序博客网 时间:2024/05/07 13:29

在屏幕竖屏的时候,我是这样处理Mat的。

“`

    private Mat matLin;//临时图像对象    mGray = inputFrame.gray();    Core.transpose(mGray, matLin);    if (camera_scene == CAMERA_FRONT) {//前置摄像头        Core.flip(matLin, mGray, 1);        //转置函数,将图像顺时针顺转(对换)        Core.flip(mGray, matLin, 0);        mGray = matLin;    } else if (camera_scene == CAMERA_BACK) {//后置摄像头        //转置函数,将图像翻转(顺时针90度)        Core.transpose(mGray, matLin);        Core.flip(matLin, mGray, 1);    }

然后在横屏的时候我还是用到了上面的代码。结果在打开Activity的时候,SurfaceView一片漆黑。看了一下log,如下:

E/CameraBridge: Utils.matToBitmap() throws an exception: /build/master_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)

E/cv::error(): OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /build/master_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp, line 97

E/org.opencv.android.Utils: nMatToBitmap catched cv::Exception: /build/master_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)

E/CameraBridge: Mat type: Mat [ 640*480*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0xffffffffb9547848, dataAddr=0xffffffff981e0020 ]

E/CameraBridge: Bitmap type: 640*480

上面的意思大概是我的bitmat的尺寸不对

也就是说,openCv的CameraBridgeViewBase接口在一开始是适配横屏显示的,只不过我为了适配竖屏,把Mat给旋转处理了,导致bitmap的尺寸不对,从而黑屏。只要在横屏的时候,把我上面的代码给注释掉,就可以运行了。

0 0