0

With Hough circle function of openCV I can detect circular patterns in an image. In particular this is my algorithm (in python)

import cv2

img = cv2.imread(in_imagefile)
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray_img = cv2.GaussianBlur(gray_img,(9,9),0)

circles = cv2.HoughCircles(gray_img, cv2.cv.CV_HOUGH_GRADIENT, dp, minDist, minRadius=minR, maxRadius=maxR)

This code is excellent in order to detect circular objects in images. (Here an example of my results:enter image description here

But when object to detect are ellipse (for example because the photo has a little of perspective) the algorithm fails. Try for example with this image: enter image description here

Is there a way to detect elliptical patterns in images? Something like HoughCircles function of openCV for ellipse, or another algorithm?

Any advice is welcome!

Davide Biraghi
  • 626
  • 1
  • 7
  • 17
  • Use the `cv2.fitEllipse()` function. – Jeru Luke Jan 11 '17 at 19:21
  • In fact this is the sense of the question. Is there a function for detect ellipse in images like houghcirles (that clearly works with circles..)? However I think that I can find useful answer [here](http://stackoverflow.com/questions/35648514/how-to-detect-ellipses-in-image-without-using-fitellipse-in-opencv). The problem is that I want a function that detect ellipses in images, not that fit them. It is different. So I think that unfortunately fitEllipse is not a solution. – Davide Biraghi Jan 12 '17 at 15:36
  • @Davide if you read the answer in the duplicate question, you'll find that it's talking about ellipse detection (and not fitting). And no, there isn't any opencv function to detect ellipses in images. – Miki Jan 13 '17 at 23:51
  • Thanks Miki. I found also [this](http://scikit-image.org/docs/dev/auto_examples/plot_circular_elliptical_hough_transform.html) method for ellipse detection with Hough transform (it is easy, but not too fast). – Davide Biraghi Jan 17 '17 at 10:14
  • @Davide that's the method of Xie that is in my answer, too ;) – Miki Jan 20 '17 at 21:37

0 Answers0