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);
}
2 | No.2 Revision |
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);
}
3 | No.3 Revision |
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);
}
4 | No.4 Revision |
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);
}