我在 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)
我不确定这是错误本身还是由其他问题引起的。
最佳答案
断言错误告诉您以下一项或多项测试失败:
src.dims == 2
info.height == (uint32_t)src.rows
info.width == (uint32_t)src.cols
我猜 info
包含目标位图的尺寸。在这种情况下,您的源 Mat 不是二维的,或者目标位图的尺寸与源 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
建议你的Mat是144x192,你的位图是384x288。看起来一个是纵向的,另一个是横向的加上你的位图是你的 Mat 分辨率的两倍。
关于android - OpenCV nMatToBitmap 断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13772704/