2012-12-07 230 views
5

我得到使用内OpenCV的一些通用的功能,下面的错误为AndroidOpenCV的nMatToBitmap断言失败

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) 

我不知道这是错误本身,或者如果它是由另一个问题引起的。

回答

9

的断言错误是告诉你,一个或多个以下测试的失败:

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 

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

+1

有人可以提出一种方法来将Mat放大到与Bitmap大小相同吗?我有同样的问题,但我仍然学习OpenCV,所以没有足够的技能... 在此先感谢! –

+0

问题最好发布为问题,而不是回答评论。一定要包含一些代码,显示目前为止您尝试过的内容以及您要完成的内容。 – SSteve

+0

你是完全正确的。我只是认为,因为这个问题紧密相关,可以在这里发布。感谢您的快速回复。 –

1

我没有足够的代表处发表评论,所以我会提供,而不是一个答案:

与“onCameraFrame”方法工作时 - 如果“垫”你回不匹配这一说法被抛出用于显示输出的框架的大小。

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

@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; 
} 
+0

其他人已经指定了我的答案 - https://stackoverflow.com/questions/37970551/opencv-resize-failing – razodactyl