Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watershed example in [android] opencv

Currently trying

<code>
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        mRgba = inputFrame.rgba();
        Imgproc.Canny(mRgba, markers, 80, 90);
        Mat threeChannel = new Mat();
        Imgproc.cvtColor(mRgba, threeChannel, Imgproc.COLOR_BGR2GRAY);
        Imgproc.watershed(threeChannel, markers);
        return threeChannel;
}

</code>

However, it fails with

CvException [org.opencv.core.CvException: /home/reports/ci/slave/50-SDK/opencv/modules/imgproc/src/segmentation.cpp:147: error: (-210) Only 8-bit, 3-channel input images are supported in function void cvWatershed(const CvArr*, CvArr*)

Could you advise how to appropriately use the markers from a Canny/Sobel edge detection to feed a Watershed algorithm? Android-specifics would be greatly helpful as this is my first Android project.

like image 551
user1296490 Avatar asked Jun 09 '26 21:06

user1296490


2 Answers

The error states that the input image for watershed() must be an 8-bit 3-channels image. After calling cvtColor(), print the number of channels of threeChannel. Don't be surprised if it outputs 1.

Pass mRgba directly to watershed() and see what happens. One of my previous answers have working code using watershed, you can use that for testing.

like image 157
karlphillip Avatar answered Jun 12 '26 10:06

karlphillip


You need to just convert your image from 4 channel to 3 channels. For example

Imgproc.cvtColor(mat , mat, Imgproc.COLOR_BGRA2BGR);
like image 39
Mehul Avatar answered Jun 12 '26 09:06

Mehul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!