Ellipse detection with OpenCV

22,951

Solution 1

One possible solution to your problem is similar to this thread Detection of coins (and fit ellipses) on an image .

You should take a look a opencv's function fitEllipse.

Solution 2

The parameters used in HoughCircles play a fundamental role. HoughCircles will detect not just perfect, but also near-perfect circles (ellipses). I suggest you check this examples:

And this answer has a decent collection of references.

Solution 3

If you already have an idea of the sizes of the ellipses that you're looking for, then try the following steps:

  • Find Canny edges in the image
  • Use a sliding window, the size of which is the maximum length of the major axis of ellipses you're looking for.
  • Within the window, collect all edge pixels, pick 6 pixels randomly and use linear least squares to fit an ellipse in the general form.
  • Repeat the above step in a RANSAC like procedure.
  • If there are enough inliers, you have an ellipse.
Share:
22,951
zeroxgames
Author by

zeroxgames

Updated on July 05, 2022

Comments

  • zeroxgames
    zeroxgames almost 2 years

    I would like to detect ellipses with OpenCV for Android, using the Tutorial 2-Basic included with OpenCV 2.4.1 package as a starting point. Note that my ellipse would be a perfect-photoshop one.

    From what I understand, using the "HoughCircles" will only find perfect (or so) circles, thus leaving ellipses out.

    Any help would be much appreciated as I am a total beginner at OpenCV

    This is what I've tried so far

        case Sample2NativeCamera.VIEW_MODE_CANNY: (ignore the Canny mode...)
    
            capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
            Imgproc.HoughCircles(mGray, mCircles, Imgproc.CV_HOUGH_GRADIENT, 1, 20);
            Log.d("Ellipse Points", " X " + mCircles.get(1,1)[0] + mCircles.get(1, 1)[1]);
    
            break;
    

    If you think any more info could be useful, please let me know.