Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV: Dominoes circular spots/disks detection

I am developing an Android app that calculates the sum of all points of the being-seen dominoes pieces -shown in picture- using OpenCV for Android.

a sample

The problem is, I can't find a way to filtering other contours and counting only dots I see in the dominoes, I tried to use Canny edge finding then use HoughCircles, but with no result, as I don't have an absolute top view of the rocks and HoughCircles detect perfect circles only :)

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 threshold is they're totally black from inside, is there anyway I could calculate the mean color/intensity for a given contour ?

like image 917
Omar Alshaker Avatar asked Dec 27 '12 17:12

Omar Alshaker


1 Answers

There is a similiar problem and possible solution on SO, titled Detection of coins (and fit ellipses) on an image. Here you will find some recomendations about opencv's function fitEllipse.

You should take a look at this for more info on opencv's function fitEllipse.

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

like image 126
Ann Orlova Avatar answered Oct 04 '22 08:10

Ann Orlova