Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ellipse detection with OpenCV

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.

like image 939
zeroxgames Avatar asked Jun 11 '12 15:06

zeroxgames


People also ask

How do you detect an ellipse in OpenCV?

To identify circles, ellipses, or in general, any shape in which the pixels are connected we use the SimpleBlobDetector() function of OpenCV.

Can OpenCV be used for object detection?

OpenCV has a bunch of pre-trained classifiers that can be used to identify objects such as trees, number plates, faces, eyes, etc. We can use any of these classifiers to detect the object as per our need.

What is blob in OpenCV?

Blob stands for Binary Large Object and refers to the connected pixel in the binary image. The term "Large" focuses on the object of a specific size, and that other "small" binary objects are usually noise.

What is cv2 approxPolyDP?

The function cv2.approxPolyDP() approximates a contour shape to another shape with less number of vertices. It accepts the following arguments − cnt − The array of the contour points. epsilon − Maximum distance from contour to approximated contour. A wise selection of epsilon is needed to get the correct output.


2 Answers

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.
like image 116
Zaphod Avatar answered Sep 17 '22 21:09

Zaphod


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.

like image 45
Rui Marques Avatar answered Sep 19 '22 21:09

Rui Marques