OpenCV: Dominoes Circular Spot / Disc Detection

I am developing an Android application that calculates the sum of all the points of the visible dominoes shown in the picture using OpenCV for Android.

a sample

The problem is that I can’t find a way to filter other contours and count only the points that I see in dominoes, I tried to use Canny edge detection and then use HoughCircles, but without result, since I do not have an absolute top view of the rocks and HoughCircles only detect perfect circles :)

Here is my code:

public Mat onCameraFrame(Mat inputFrame) { inputFrame.copyTo(mRgba); Mat grey = new Mat(); // Make it greyscale Imgproc.cvtColor(mRgba, grey, Imgproc.COLOR_RGBA2GRAY); // init contours arraylist List<MatOfPoint> contours = new ArrayList<MatOfPoint>(200); //blur Imgproc.GaussianBlur(grey, grey, new Size(9,9), 10); Imgproc.threshold(grey, grey, 80, 150, Imgproc.THRESH_BINARY); // because findContours modifies the image I back it up Mat greyCopy = new Mat(); grey.copyTo(greyCopy); Imgproc.findContours(greyCopy, contours, new Mat(), Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_NONE); // Now I have my controus pefectly MatOfPoint2f mMOP2f1 = new MatOfPoint2f(); //a list for only selected contours List<MatOfPoint> SelectedContours = new ArrayList<MatOfPoint>(400); for(int i=0;i<contours.size();i++) { if(here I should put a condition that distinguishes my spots, eg: if contour inside is black and is a black disk) { SelectedContours.add(contours.get(i)); } } Imgproc.drawContours(mRgba, SelectedContours, -1, new Scalar(255,0,0,255), 1); return mRgba; } 

EDIT:

One unique feature of my contours after the threshold is that they are completely black inside, is there anyway I could calculate the average color / intensity for a given contour?

+8
java android opencv
source share
1 answer

There is a similar problem and a possible solution on SO called Coin Detection (and corresponding ellipses) in the image . Here you will find recommendations on opencv function fitEllipse .

You can look for more information on the fitEllipse opencv function .

In addition, to detect only black image elements, you can use the HSV color model to find only black colors. You can find an explanation here .

+5
source share

All Articles