I am using OpenCV to detect ellipses in a binary image as shown below. In the image, there are eight ellipses to be detected. I can use findContours to obtain a lot of contours including the eight ellipses. The problem is: how can I judge and which one is ellipse which one is not? How to remove all the other false detections?
False Positive is reduced by training on weakly labelled negative samples. Negative examples are also used in Contrastive Learning type unsupervised methods. Where distance between positive and negative images are increased in the latent space [12].
In this specific case, the Hough Circle Transform is probably the easiest solution.
Copy the code from the tutorial and change the parameters of cv::HoughCircles()
to:
/// Apply the Hough Transform to find the circles
HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 1, 10, 40, 30, 0, 0 );
Output:
But I loved @George's idea, go with it, it's more robust than specifying hardcoded constants. My approach works great for this image, but if you have images with different sizes of circles and stuff, you want to use cv::minEnclosingCircle()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With