简体   繁体   中英

Detect different kinds of circles and ovals on the image using OpenCV and Python

I need to detect the different shapes on the image such as ellipses and circles with a dashed-border.

Using OpenCV causes some troubles, for eg openCV detects not a contour but an amount of small separated lines(contours). In case of ellipse with a "dashed-border" I need it to be as single contour, not a separated objects.

What would you suggest to solve this problem?

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

Ellipse with solid border

在此处输入图片说明

Ellipse with dashed border:

在此处输入图片说明

The Hough transform should not have any troubles with either dashed or solid borders, or a mix thereof. I have used it to detect dashed lines in one of my project and ellipses should not be much harder.

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

The better idea there is to use an specific transform to detect circle and ellipses rather than a general "find contour" call.

I am not enough acquainted with OpenCV to know if there this sort of detection is built in there - it should be.

An internet search for the more generic "image ellipse detection" shows it is not a settled matter - unlike square and rectangle detection, so whatever OpenCV already contains will have to be tunned up. (The basic idea is that the underlying algorithm creates a new n-dimensional space where every possible paramterized ellipse for the target image could be represented (with, for example, an axis for each x and y center coordinates, w and h radii, and one for rotation), and fill in hits in this matrix according to the pixels contrast in the target image).- Sebastian's answer put the correct name for this approach I could not recall: "Hough transform", and provides the needed links on how it works, and how to extend it on OpenCV.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM