Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

you converted your src img to grayscale, so you can't draw something 'red' into it.

(actually, Scalar(255,0,0) would have resulted in a white shape, it only looks at the 1st component for b/w drawing))

keep your bgr src image for later drawing:


Mat src = new Mat();
Utils.bitmapToMat(bmp, src);
Mat gray = new Mat();
Imgproc.cvtColor(src, gray, Imgproc.COLOR_RGBA2GRAY);

Imgproc.Canny(gray, gray, 50, 200);
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
// find contours:
Imgproc.findContours(gray, contours, hierarchy, Imgproc.RETR_TREE,Imgproc.CHAIN_APPROX_SIMPLE);
for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
    Imgproc.drawContours(src, contours, contourIdx, new Scalar(0, 0, 255), -1);
}

you converted your src img to grayscale, so you can't draw something 'red' into it.

(actually, Scalar(255,0,0) would have resulted in a white shape, it only looks at the 1st component for b/w drawing))

keep your bgr src image for later drawing:


Mat src = new Mat();
Utils.bitmapToMat(bmp, src);
Mat gray = new Mat();
Imgproc.cvtColor(src, gray, Imgproc.COLOR_RGBA2GRAY);

Imgproc.Canny(gray, gray, 50, 200);
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
// find contours:
Imgproc.findContours(gray, contours, hierarchy, Imgproc.RETR_TREE,Imgproc.CHAIN_APPROX_SIMPLE);
for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
    Imgproc.drawContours(src, contours, contourIdx, new Scalar(0, 0, 255), -1);
}

image description

you converted your src img to grayscale, so you can't draw something 'red' into it.

(actually, Scalar(255,0,0) would have resulted in a white shape, it only looks at the 1st component for b/w drawing))

keep your bgr src image for later drawing:


Mat src = new Mat();
Utils.bitmapToMat(bmp, src);
Mat gray = new Mat();
Imgproc.cvtColor(src, gray, Imgproc.COLOR_RGBA2GRAY);

Imgproc.Canny(gray, gray, 50, 200);
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
// find contours:
Imgproc.findContours(gray, contours, hierarchy, Imgproc.RETR_TREE,Imgproc.CHAIN_APPROX_SIMPLE);
for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
    Imgproc.drawContours(src, contours, contourIdx, new Scalar(0, 0, 255), -1);
}

image descriptionimage description

you converted your src img to grayscale, so you can't draw something 'red' into it.

(actually, Scalar(255,0,0) would have resulted in a white shape, it only looks at the 1st component for b/w drawing))drawing, and yours is unfortunately 0, resulting in an all black img)

keep your bgr src image for later drawing:


Mat src = new Mat();
Utils.bitmapToMat(bmp, src);
Mat gray = new Mat();
Imgproc.cvtColor(src, gray, Imgproc.COLOR_RGBA2GRAY);

Imgproc.Canny(gray, gray, 50, 200);
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
// find contours:
Imgproc.findContours(gray, contours, hierarchy, Imgproc.RETR_TREE,Imgproc.CHAIN_APPROX_SIMPLE);
for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
    Imgproc.drawContours(src, contours, contourIdx, new Scalar(0, 0, 255), -1);
}

image description