我在使用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)
我不确定这是错误本身还是由其他问题引起的。
答案 0 :(得分:13)
断言错误告诉您以下一项或多项测试失败:
src.dims == 2
info.height == (uint32_t)src.rows
info.width == (uint32_t)src.cols
我猜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
建议你的Mat是144x192,你的位图是384x288。看起来一个是肖像,另一个景观加上你的位图是你Mat的分辨率的两倍。
答案 1 :(得分:3)
我没有足够的代表发表评论,所以我会提供一个答案:
使用'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, // Scale back down to 640x480 (original dim.)
Imgproc.resize(resizeImage, afterResize, szAfter);
return afterResize;
}