抛出了Mat to Bitmap异常

时间:2016-07-05 06:34:52

标签: android opencv bitmap mat

以下是我在openCV中绘制边框的代码

Mat src = new Mat(imageChosen.getWidth(), imageChosen.getHeight(), CvType.CV_8UC3);
Utils.bitmapToMat(imageChosen, src);
Mat dst = new Mat(imageChosen.getWidth(), imageChosen.getHeight(), CvType.CV_8UC3);
Core.copyMakeBorder(src, dst, 10, 10, 10, 10, Core.BORDER_CONSTANT, new Scalar(0,0,0));
Bitmap b = Bitmap.createBitmap(imageChosen.getWidth()+20, imageChosen.getHeight()+20,Bitmap.Config.ARGB_8888);
Utils.matToBitmap(src, b);

我不知道为什么抛出

E/cv::error(): 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 /Volumes/Linux/builds/master_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp, line 97
E/org.opencv.android.Utils: nMatToBitmap catched cv::Exception: /Volumes/Linux/builds/master_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp:97: 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)

非常感谢任何帮助/想法,谢谢。

1 个答案:

答案 0 :(得分:0)

如果您查看Mat的{​​{3}},您可以看到构造函数按以下顺序期望其params:行,列。

您首先传递宽度(列),然后传递高度(行)。

而不是以下内容:

Mat src = new Mat(imageChosen.getWidth(), imageChosen.getHeight(), CvType.CV_8UC3);

你应该首先传递高度:

Mat src = new Mat(imageChosen.getHeight(), imageChosen.getWidth(), CvType.CV_8UC3);

适用于srcdst