detect circle is filled or not. [closed]
i am trying to detect if it is filled or not from a small image which i cropped from another doc in order to run character recognition using google vision and the check the circle is filled or not. the sample image are like this
though the image process i programmed is working and returning correct value but it is returning two circles for each picture whether filled and not filled which i dont want as each value is appending in my recycler view and meesing the itemView Group.
public String CircleDetection(Bitmap bitmap){
String timeStamp = new SimpleDateFormat("yyyyMMdd_mmHH").format(new Date());
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/sams_images"+"/"+timeStamp);
myDir.mkdir();
String chunkedImagedDirectory = myDir.toString() + "/";
Mat localMat1 = new Mat();
Utils.bitmapToMat(bitmap, localMat1);
Mat localMat2 = new Mat();
Imgproc.GaussianBlur(localMat1, localMat2, new Size(5, 5), 7);
Object localObject = new Mat();
Imgproc.cvtColor(localMat2, (Mat)localObject, COLOR_RGB2GRAY);
Mat cloneMat= ((Mat) localObject).clone();
localMat2 = localMat1.clone();
bitwise_not(cloneMat,cloneMat);
Imgproc.threshold(cloneMat,localMat2,127,255,Imgproc.THRESH_OTSU);
Mat thresh=localMat2.clone();
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(localMat2, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
for (int i =0 ; i < contours.size(); i++) {
Rect rectCrop = boundingRect(contours.get(i));
//creating crop of that contour from actual image
if((rectCrop.height/rectCrop.width > 0.8) && (rectCrop.height/rectCrop.width < 1.2) && rectCrop.height > 30 && rectCrop.width >30){
Mat imageROI= thresh.submat(rectCrop);
//apply countnonzero method to that crop
int total = countNonZero(imageROI);
double pixel = total / contourArea(contours.get(i)) * 100;
//pixel is in percentage of area that is filled
if (pixel >= 100 && pixel <= 130) {
//counting filled circles
attendanceText = "Present";
String chunkedfilename = chunkedImagedDirectory +i+ "present" + "h" + rectCrop.height + "w" + rectCrop.width + ".jpg";
Imgcodecs.imwrite(chunkedfilename, imageROI);
} else {
attendanceText = "Absent";
String chunkedfilename = chunkedImagedDirectory +i+"absent" + "h" + rectCrop.height + "w" + rectCrop.width + ".jpg";
Imgcodecs.imwrite(chunkedfilename, imageROI);
break;
}
}
}
return attendanceText;
}
Though its this process returning correct value but detecting two individual circle in case of filled and not filled even though i am providing the setting the parameter once in the function How can i detect the circle only once either fill or empty only once..?
Now that you have your images cropped, you can run findContours on the images. If there are 2 resulting contours, then the circle is not filled. If there is 1 resulting contour, then the circle is filled. Or is it the other way around........? Anyway, findContours will do the trick for you. I don't know Java, and I don't plan on learning it.
I have some C++ code that gets the contours in an image: https://github.com/sjhalayka/opencv_c...