OpenCV nMatToBitmap断言失败

ali*_*air 8 java-native-interface android opencv android-ndk

我在使用OpenCV for Android中的一些通用函数时遇到以下错误

12-05 21:08:55.486: E/cv::error()(6658): 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 /home/oleg/sources/opencv/modules/java/generator/src/cpp/utils.cpp, line 107
12-05 21:08:55.486: E/org.opencv.android.Utils(6658): nMatToBitmap catched cv::Exception: /home/oleg/sources/opencv/modules/java/generator/src/cpp/utils.cpp:107: 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)
12-05 21:08:55.486: E/CameraBridge(6658): Mat type: Mat [ 144*192*CV_8UC3, isCont=true, isSubmat=false, nativeObj=0x1024c0, dataAddr=0x44783010 ]
12-05 21:08:55.486: E/CameraBridge(6658): Bitmap type: 384*288
12-05 21:08:55.486: E/CameraBridge(6658): Utils.matToBitmap() throws an exception: /home/oleg/sources/opencv/modules/java/generator/src/cpp/utils.cpp:107: 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)
Run Code Online (Sandbox Code Playgroud)

我不确定这是错误本身还是由其他问题引起的.

SSt*_*eve 15

断言错误告诉您以下一个或多个测试失败:

src.dims == 2
info.height == (uint32_t)src.rows
info.width == (uint32_t)src.cols
Run Code Online (Sandbox Code Playgroud)

我猜测info包含目标位图的尺寸.在这种情况下,您的源Mat不是2维,或者目标位图的尺寸与源Mat的尺寸不匹配.

这两行

12-05 21:08:55.486: E/CameraBridge(6658): Mat type: Mat [ 144*192*CV_8UC3, isCont=true, isSubmat=false, nativeObj=0x1024c0, dataAddr=0x44783010 ]
12-05 21:08:55.486: E/CameraBridge(6658): Bitmap type: 384*288
Run Code Online (Sandbox Code Playgroud)

建议你的Mat是144x192,你的位图是384x288.看起来一个是肖像,另一个景观加上你的位图是你Mat的分辨率的两倍.


raz*_*tyl 5

我没有足够的代表来发表评论,所以我将提供一个答案:

使用“onCameraFrame”方法时 - 如果返回的“mat”与用于显示输出的帧的大小不匹配,则会抛出此断言。

换句话说 - 如果您要调整大小以进行某种处理,请确保在将其返回到显示器之前将其恢复到原始大小。

@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame 
inputFrame) {
    mRgba = inputFrame.rgba();

    Mat resizeImage = new Mat();
    Size sz = new Size(800, 600); // Scale up to 800x600
    Imgproc.resize(mRgba, resizeImage, sz);

    // Do some sort of processing here on resized image.

    Mat afterResize = new Mat();
    Size szAfter = new Size(640, 480); // Scale back down to 640x480 (original dim.)
    Imgproc.resize(resizeImage, afterResize, szAfter);

    return afterResize;
}
Run Code Online (Sandbox Code Playgroud)