Detecting various circles and ovals in an image using OpenCV and Python

I need to define various shapes in the image, such as ellipses and dashed circles.

Using OpenCV causes some problems, for example. openCV does not detect a path, but the number of small divided lines (paths). In the case of an ellipse with a "dotted border", I need it to be as a single contour, and not separate objects.

What do you propose to solve this problem?

I also need to recognize ellipses (or circles) with solid borders and ellipses (circles) with a dashed border

Solid frame ellipse

enter image description here

Dotted ellipse:

enter image description here

+5
source share
2 answers

The Hough transform should not have any problems with dashed or solid borders, or a combination of them. I used it to detect dashed lines in one of my projects, and ellipses should not be much more complicated.

OpenCV by default implements the Hough transform for circles and straight lines , but there is a blog post with code on how to adapt it for elliptical shapes.

+4
source

A better idea is to use a special transform to define a circle and ellipses, rather than a general search outline call.

I'm not familiar enough with OpenCV to find out if such a detection exists there - it should be.

An Internet search for a more general “image ellipse detection” shows that this is not a settled issue — unlike squares and rectangles, so everything that OpenCV already contains must be set up. (The basic idea is that the basic algorithm creates a new n-dimensional space where any possible parameterized ellipse for the target image can be represented (for example, the axis for each coordinate of the center x and y, w and h with radii and one for rotation) and fill hits in this matrix in accordance with the contrast of pixels in the target image). Sebastian’s answer names the correct name for this approach, which I couldn’t remember: “Hough Transformation” and provides the necessary links on how it works and how to extend it on OpenCV.

0
source

All Articles