3

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.

user1296490
  • 97
  • 1
  • 5
  • 13
  • Have you managed to solve your problem showing plain white image? I am facing similar issue right now and can't find any solutions. – John Yang Oct 09 '13 at 14:13

2 Answers2

4

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.

Community
  • 1
  • 1
karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • Cheers, the original image mRgba had 4 channels, so I used `COLOR_BGRA2BGR` instead of `COLOR_BGR2GRAY`. Now the problem is Canny returns `CV_8UC1` as markers output, while `watershed` expects 32-bit single-channel image. I used `mIntermediateMat.convertTo(mIntermediateMat, CvType.CV_32S);` but the result of the watershed is a plain white image. Any suggestions to what has gone wrong? Maybe the conversion from 8bit unsigned to 32 bit signed messes it up – nmadzharov Mar 24 '13 at 22:59
  • Let's fix one issue at a time. Feel free to ask another question in another thread. Don't forget to up vote my answer if it helped you, or click on the checkbox near it to select it as the official problem solver. I would love to see your new code in a new question. – karlphillip Mar 24 '13 at 23:14
  • Cannot really post another question as it is still the same one – nmadzharov Mar 24 '13 at 23:25
  • Not at all, your question changed completely. You came here to discover why this specific error was happening and how to fix it, and I believe that was solved. You might be working on the same source code, but now you are asking a different question about it. To ask this new question in this thread you would have to completely rewrite the question and update the source code, and that would be a shame, because we would information about this problem and how to solve it. Not to mention that I would have to completely rewrite my answer to address the new problem. – karlphillip Mar 24 '13 at 23:35
  • @karlphillip I've been trying to develop a kotlin app for weeks that will target a region of interest in wound images. I need the user to use the touch of the device's screen to draw the surroundings of the region of interest, so that the watershed can segment only that region and change the background color to black. I really need to do this and I can't get help from anyone, you can help me with this, please. – Tecnologia da Net May 18 '20 at 19:55
1

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

Imgproc.cvtColor(mat , mat, Imgproc.COLOR_BGRA2BGR);
Mehul
  • 2,141
  • 1
  • 15
  • 15