Find the number of white pixels in contour
I have an image and I'm trying to find the filled circles inside image (MCQ's).
I have found all contours and when drawing its drawing the circles but now I don't know how to find the number of white pixels inside contour. Image is in binary pealse suggest something. Thanks
java.util.List<MatOfPoint> contours_crop = new ArrayList<MatOfPoint>();
Imgproc.findContours(crop.clone(), contours_crop, new Mat() ,Imgproc.RETR_EXTERNAL , Imgproc.CHAIN_APPROX_SIMPLE);
//Imgproc.cvtColor(crop, crop, Imgproc.COLOR_GRAY2BGR);
double noPixels = Core.countNonZero(contours_crop.get(3));
Toast.makeText(MainActivity.this, "Pixels:"+noPixels, 10000).show();
nope, you can't use countNonZero with contours, only with images.
so what @berak is trying to say
i added the image from the crossposted SO question for clarity. again, it seems to be about finding the filled circles. so my proposal would be either:
or:
(this will only work on convex objects, like the circles, but probably fail on e.g. the '1' there)
Getting the boundingrect() and then counting non zero helped :)
Hello Zain can you share the solution here also so that even I can get some help out of it Thanks