Hi,
I am trying to detect the count of objects in an image captured on which several operations are performed. I capture an image, get the Hue channel and apply the following:
Imgproc.cvtColor(srcMat, dst, Imgproc.COLOR_RGB2HSV);
ArrayList<Mat> channels = new ArrayList<Mat>();
Core.split(srcMat, channels);
Mat satImg = channels.get(0);
Imgproc.medianBlur(satImg , satImg , 11);
Highgui.imwrite(imgPath + "blurred.jpg", satImg);
Imgproc.threshold(satImg, satImg, -1, 255, Imgproc.THRESH_BINARY + Imgproc.THRESH_OTSU);
Highgui.imwrite(imgPath + "satImg_thresh.jpg", satImg);
Once thresholding is applied to the image, i apply a gaussian blur and apply a threshold filter again, and then a bitwise_not
operation on the image . Dilation is applied and then edges are obtained using:
Mat edge = new Mat();
Imgproc.Canny(satImg, edge, 35,90); // 40,120 -> to tr
Log.e("tag","edge: " + edge.cols());
edge.convertTo(threshMat,CvType.CV_8U);
Log.e("tag","dst cols " + threshMat.cols());
Highgui.imwrite(imgPath + "canny.jpg", threshMat);
This is the image i get:
I then perform dilation out of which i get the image below:
There are a couple of questions i have:
I would like to actually fill those edges completely such that it would become a complete ellipse. Yes, i am using
fitEllipse
for the same but i would like to do it with an edge function if possible. I am usingfindContours
to get the number of outer edges with the flatImgproc.RETR_EXTERNAL
but then as in the image there is that one line extra that gets counted, i wish to neglect that too. Could any one please guide me ?Sometimes shadows also form a polygon, i would like to ignore shadows also
Is there a way i could only take into picture those contours that are ellipses or circles? Not lines that turn out to be ellipses, and not even those minor dots if there are any.
Please assist
P.S: I am using opencv for android, any help with c++ code is welcome, though i wish an android equivalent would be present.