10

我在使用 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)

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

4

2 回答 2

18

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

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 分辨率的两倍。

于 2012-12-08T00:11:03.840 回答
4

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

使用 '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;
}
于 2017-07-12T08:45:25.360 回答