Exception about copyMakeBorder and matToBitmap [closed]

asked 2016-07-05 05:36:22 -0600

BaKa gravatar image

updated 2018-10-26 15:46:20 -0600

When i use the following code,

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

it throw such exception:

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)

Do any one have idea what's wrong is my code ?

Any help/ideas would be greatly appreciated, thanks a lot.

edit retag flag offensive reopen merge delete

Closed for the following reason not a real question by BaKa
close date 2016-07-05 05:49:03.075377

Comments

  • please try not to pre-allocate Mats for results, dst = new Mat() should do (and your size is wrong anyway)

  • please check the type of the input. if it is CV_8UC3(color), then your preallocations are wrong(again), if it is CV_8U, then Bitmap.Config.ARGB_8888 is the wrong flag (does not match a single8bit chan)

berak gravatar imageberak ( 2016-07-05 05:43:04 -0600 )edit

I discover that i set the matToBitmap(); wrongly, not src but dst

BaKa gravatar imageBaKa ( 2016-07-05 05:50:03 -0600 )edit

btw, thanks for answering :)

BaKa gravatar imageBaKa ( 2016-07-05 05:50:15 -0600 )edit