Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect ellipses in image without using fitEllipse() in opencv?

I am trying to detect elliptical kernels, in OpenCV using C++. I have tried obtaining Canny edges, and then using fitEllipse() function on the edges. Though this finds ellipses, the accuracy is horrid when the image is noisy, or if there are many edges.

I have realised that the way to go is detecting ellipses, and not fitting them. Maybe something like Hough circles, but for ellipses? I also do not know the length the ellipses could be, as it varies between images.

Can anybody help me get started on that? All related answers are very vague, and I just want pointers on where to start.

Fitted Ellipses on Canny Edges

like image 281
Brindha Avatar asked Feb 26 '16 09:02

Brindha


1 Answers

As you already got, you don't need ellipse fitting, but ellipse detection.

You can find in my other answer two papers with C++ code available. I'll report here for completeness:

  1. L. Libuda, I. Grothues, K.-F. Kraiss, Ellipse detection in digital image data using geometric features, in: J. Braz, A. Ranchordas, H. Arajo, J. Jorge (Eds.), Advances in Computer Graphics and Computer Vision, volume 4 of Communications in Computer and Information Science, Springer Berlin Heidelberg, 2007, pp. 229-239. link, code

  2. M. Fornaciari, A. Prati, R. Cucchiara, "A fast and effective ellipse detector for embedded vision applications", Pattern Recognition, 2014 link, code

It's also fairly easy to port to OpenCV this matlab script with the implementation of the two papers:

  • "A New Efficient Ellipse Detection Method" (Yonghong Xie Qiang , Qiang Ji / 2002)
  • "Randomized Hough Transform for Ellipse Detection with Result Clustering" (CA Basca, M Talos, R Brad / 2005)

Another very interesting algorithm is:

  • Dilip K. Prasad, Maylor K.H. Leung and Siu-Yeung Cho, “Edge curvature and convexity based ellipse detection method,” Pattern Recognition, 2012.

Matlab code can be found here


Directly applying Hough Transform is not feasible for an ellipse, since you'll work in a 5 dimensional parameter space. This will be really slow, and not accurate. So a lot of algorithms have been proposed. Among the ones mentioned here:

  • Xie and Ji approach is quite famous and very easy (but still slow)
  • Basca et al. approach is faster, but may be not accurate
  • Prasad et al. approach is fast, and very accurate.
  • Libuda et al. approach is very fast and accurate
  • Fornaciari et al. approach is the fastest, but may be inaccurate in particular cases.

For the up-to-date bibliography for ellipse detection, you can refer to this page.

like image 128
Miki Avatar answered Nov 09 '22 06:11

Miki