2016-07-05 101 views
1

以下是我在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) 

任何幫助/意見將不勝感激,謝謝。

回答

0

如果您看一下Matdocumentation,您可以看到構造函數按照以下順序期望它的參數:rows,columns。

您先傳遞寬度(列),然後傳遞高度(行)。

取而代之的是以下內容:

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

你應該先通過高度:

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

對於這兩種srcdst