0

I have just recently started to work with OpenCV and image processing in general, so please bear with me

I have the following image to work with: o

The gray outline is the result of the tracking algorithm, which I drew in for debugging, so you can ignore that.

I am tracking glowing spheres, so it is easy to turn down the exposure of my camera and then filter out the surrounding noise that remains. So what I have to work with is always a black image with a white circle. Sometimes a little bit of noise makes it through, but generally that's not a problem.

Note that the spheres are mounted on a flat surface, so when held at a specific angle the bottom of the circle might be "cut off", but the Hough transform seems to handle that well enough..

Currently, I use the Hough Transform for getting position and size. However, it jitters a lot around the actual circle, even with very little motion. When in motion, it sometimes loses track entirely and does not detect any circles.

Also, this is in a real-time (30fps) environment, and i have to run two Hough circle transforms, which takes up 30% CPU load on a ryzen 7 cpu...

I have tried using binary images (removing the "smooth" outline of the circle), and changing the settings of the hough transform. With a lower dp value, it seems to be less jittery, but it then is no longer real-time due to the processing needed.

This is basically my code:

ImageProcessing.ColorFilter(hsvFrame, Frame, tempFrame, ColorProfile, brightness);
ImageProcessing.Erode(Frame, 1);
ImageProcessing.SmoothGaussian(Frame, 7);
/* Args: cannyThreshold, accumulatorThreshold, dp, minDist, minRadius, maxRadius */
var circles = ImageProcessing.HoughCircles(Frame, 80, 1, 3, Frame.Width / 2, 3, 80);
if (circles.Length > 0)
    ...    

The ImageProcessing calls are just wrappers to the OpenCV framework (EmguCV)

Is there a better, less jittery and less performance-hungry way or algorithm to detect these kinds of (as i see it) very simple circles? I did not find an answer on the internet that matches these kinds of circles. thank you for any help!

Edit: This is what the image looks like straight from the camera, no processing: enter image description here

Twometer
  • 1,561
  • 2
  • 16
  • 24
  • 2
    use contour extraction and minEnclosingCircle function. If you have a lot of noise but always a circle, try RANSAC circle detection – Micka Aug 16 '20 at 09:42
  • Can we see the original, unprocessed image ? And one with motion ? Without this we are answering an XY question. –  Aug 16 '20 at 10:36
  • @Micka: I would not trust the minEnclosingCircle, as it uses just three points to fit the circle, making it very sensitve to noise. –  Aug 16 '20 at 10:40
  • you can use sanity checks like area comparison as in https://stackoverflow.com/questions/17159964/opencvs-fitellipse-sometimes-returns-completely-wrong-ellipses or testing edge distances. If normally, circle and background can be separated well, minEnclosingCircle is great and simple. For settings with known number of circles I love RANSAC. – Micka Aug 16 '20 at 12:11
  • @YvesDaoust With the unprocessed, do you mean the raw footage from the camera? Because that's basically just what you see in the picture I uploaded, with more noise and not color-filtered. – Twometer Aug 16 '20 at 15:59
  • 1
    @Micka I have tried the contour extraction with MinEnclosingCircle and that works really well; i will be testing that more later when I have time, thanks for that suggestion! Only problem is that sometimes it does not detect the contour randomly. – Twometer Aug 16 '20 at 16:44
  • @Twometer: raw images are always necessary. Always. And uncompressed. Always. –  Aug 16 '20 at 17:01
  • @YvesDaoust I have added a raw image – Twometer Aug 16 '20 at 18:38
  • Why the downvote? – Twometer Aug 16 '20 at 18:39
  • This image has clearly suffered significant JPEG compression. Use the blue channel, which is the most contrasted. But the shape is not a perfect circle and does not correspond to the binarized one. As I anticipated, the raw image shows a different thing. –  Aug 16 '20 at 18:50

1 Answers1

5

I feel desperate to see how often people spoil good information by jumping on edge detection and/or Hough transformations.

In this particular case, you have a lovely blob, which can be detected in a fraction of a millisecond and for which the centroid will yield good accuracy. The radius can be obtained just from the area.

You report that in case of motion the Hough becomes jittery; this can be because of motion blur or frame interleaving (depending on the camera). The centroid should be more robust to these effects.