bug in image segmentation with watershed demo of openCV docs

asked 2019-05-13 08:19:07 -0600

Vq14x gravatar image

updated 2019-05-18 21:44:51 -0600

supra56 gravatar image

I tried to get up the following demo on Android (Java): https://docs.opencv.org/3.4.3/d2/dbd/... but it crashes on running:

    // Perform the watershed algorithm
    Imgproc.watershed(imgResult, markers);

The error message is:

"E/cv::error(): OpenCV(3.4.6) Error: Assertion failed (src.type() == CV_8UC3 && dst.type() == CV_32SC1) in void cv::watershed(cv::InputArray, cv::InputOutputArray), file /build/3_4_pack-android/opencv/modules/imgproc/src/segmentation.cpp, line 161 E/org.opencv.imgproc: imgproc::watershed_10() caught cv::Exception: OpenCV(3.4.6) /build/3_4_pack-android/opencv/modules/imgproc/src/segmentation.cpp:161: error: (-215:Assertion failed) src.type() == CV_8UC3 && dst.type() == CV_32SC1 in function 'void cv::watershed(cv::InputArray, cv::InputOutputArray)'"

Only changes I did was the kind of loading the image:

Mat srcOriginal =
Utils.loadResource(SuperActivity.context_MainActivity,
R.mipmap.cards);

But I think that shouldn't be the problem...

I'm grateful for every help, because I already tried a lot in fixing it.

edit retag flag offensive close merge delete

Comments

1

Only changes I did was the kind of loading the image:

that usually IS the problem ! please check srcOriginal.empty() (expected:false) and srcOriginal.type() (expected:16)

your image might be not loaded at all, or have the wrong number of channels (android usess bgra mostly)

berak gravatar imageberak ( 2019-05-19 02:31:36 -0600 )edit