Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The problem is that you do not correctly initialize the Mat you want to draw on. You currently want to draw on an empty Mat. That makes no sense. You can take the size of any img Mat you have (result, tmpMat, canny) and initialize the Mat with zeros.

 Mat mask = Mat::zeros( canny.size(), CV_8UC3);
 Imgproc.drawContours(mask, contours, 0 , new Scalar(255)

The problem is that you do not correctly initialize the Mat you want to draw on. You currently want to draw on an empty Mat. That makes no sense. You can take the size of any img Mat you have (result, tmpMat, canny) and initialize the Mat with zeros.

 Mat mask = Mat::zeros( Mat.zeros( canny.size(), CV_8UC3);
 Imgproc.drawContours(mask, contours, 0 , new Scalar(255)
Scalar(255))

Btw, I noticed an error. You convert from RGB2BGRA, but then only from BGR2GRAY. Maybe just convert RGB2BGR first.