12

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.

zeroxgames
  • 630
  • 2
  • 9
  • 13

3 Answers3

7

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.

Community
  • 1
  • 1
Rui Marques
  • 6,898
  • 3
  • 48
  • 82
5

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.

Community
  • 1
  • 1
karlphillip
  • 87,606
  • 33
  • 227
  • 395
4

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.
Zaphod
  • 1,907
  • 10
  • 13