我正在使用OpenCV-2.4.8 android sdk
的Android應用程序。 以下示例代碼嘗試使用OpenCV
庫的Watershed segmenter algorithm
來檢測對象。OpenCV錯誤:斷言失敗(scn == 3 || scn == 4)在OpenCV中使用分水嶺android sdk
//bmp is the source bitmap that I am reading from a Drawable resource.
Mat mBackgroundMat = new Mat(new Size(bmp.getWidth(), bmp.getHeight()), CvType.CV_8UC3);
Utils.bitmapToMat(bmp, mBackgroundMat);
//Initialize the Mat Objects
Mat backgroundMat = new Mat();
Mat greyMatImg = new Mat();
Mat thresholdImg = new Mat();
Mat markerImg = new Mat();
//Erode and dillate
Imgproc.erode(mBackgroundMat, backgroundMat, new Mat(), new Point(-1, -1), 12);
Imgproc.dilate(backgroundMat, backgroundMat, new Mat(), new Point(-1, -1), 12);
// Imgproc.cvtColor(backgroundMat, backgroundMat, Imgproc.COLOR_RGB2BGR);
Imgproc.cvtColor(backgroundMat, greyMatImg, Imgproc.COLOR_BGR2GRAY);
Imgproc.threshold(greyMatImg, thresholdImg, 0, 255, Imgproc.THRESH_BINARY_INV);
Imgproc.distanceTransform(thresholdImg, markerImg, Imgproc.CV_DIST_L2, Imgproc.CV_DIST_MASK_5);
Imgproc.cvtColor(thresholdImg, thresholdImg, Imgproc.COLOR_GRAY2BGR, 3);
Mat tempMat = new Mat(markerImg.rows(), markerImg.cols(), CvType.CV_32SC1);
Imgproc.cvtColor(markerImg, tempMat, CvType.CV_32SC1, 0);
Imgproc.watershed(thresholdImg, tempMat);
//Release unused mats.
tempMat.release();
backgroundMat.release();
greyMatImg.release();
markerImg.release();
//Output thresholdImg
我收到以下錯誤:
cv::error()(2566): OpenCV Error: Assertion failed (scn == 3 || scn == 4) in void cv::cvtColor(InputArray, OutputArray, int, int), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/color.cpp, line 3648
請幫我找出我在做什麼錯在這裏。
嘗試這個。仍然得到相同的錯誤。 –
對不起 - 我的意思是做convertTo,而不是此時調用cvtColor。 – timegalore