Why is the drawContour() in OpenCV generating this strange Mask?
I started by reading in a Mat
.
Then I converted it to Greyscale and applied Imgproc.canny()
to it, getting the following mask.
Then I used Imgproc.findContours()
to find the contours, Imgproc.drawContours()
, and Core.putText()
to label the contours with numbers
Then I did Rect boundingRect = Imgproc.boundingRect(contours.get(0));
Mat submatrix = new Mat();
submatrix = originalMat.submat(boundingRect);
to get following submatrix
:
So far so good. The Problem starts hereafter:
NOW I NEEDED A MASK OF THE submatrix
. So I decided to use Imgproc.drawContours()
to get the mask:
Mat mask = new Mat(submatrix.rows(), submatrix.cols(), CvType.CV_8UC1);
List<MatOfPoint> contourList = new ArrayList<>();
contourList.add(contours.get(0));
Imgproc.drawContours(mask, contourList, 0, new Scalar(255), -1);
I got the following mask:
WHAT I WAS EXPECTING was a filled (in white color) diamond shape on black background.
WHy am I getting this unexpected result?