1 | initial version |
these lines are the key
Mat dilatedMask = new Mat();
Imgproc.dilate(mask, dilatedMask, new Mat());
Imgproc.dilate(dilatedMask, dilatedMask, new Mat());
you could try changing like
Mat dilatedMask = new Mat();
Imgproc.erode(mask, dilatedMask, new Mat());
Imgproc.erode(dilatedMask, dilatedMask, new Mat());
or to draw exact contour of blob
Mat dilatedMask = mask.clone();