Ball / Circle Detection in OpenCV (C ++)

I am trying to detect a ball in a filtered image. In this image, I have already deleted material that cannot be part of the object. Of course, I tried the HoughCircle function, but I did not get the expected result. Either he did not find the ball, or too many circles were discovered. The problem is that the ball is not completely round .

Screenshots:

enter image description here

I had the idea that it can work if I identify individual objects, calculate their center and check if the radius is approximately the same in different directions. But it would be nice if he found the ball also, if it is not completely visible. And with this method, I canโ€™t detect the semicircles or something like that.

EDIT . These images are taken from the video stream (in real time).

What other method can I try?

enter image description here

+5
source share
1 answer

Looks like you used difference visualization or something similar to get the images you have.? Instead of finding circles, find a more general loop. Suggestions:

  • Separate all connected components.
  • For each connected component -
  • Go around the outline and collect all the outline pixels in the list
  • Proposition 1: use the least squares to match the ellipse to the contour points.
  • Proposition 2: Examine the curvature of each pixel in the path and check if it matches a circle or ellipse. This check can be performed by calculating a histogram of the edge orientations for the outline pixels or by checking the orientation gradients from the outline pixel to the outline pixel. In the second case, for the circle or ellipse, the gradients should be almost the same (ask me if this is not entirely clear).
  • Apply restrictions on the perimeter, area, lengths of primary and secondary axes, etc. ellipse or loop. Collect these properties as functions.
  • You can use hardcoded heuristics / thresholds to classify a feature set as a ball / non-ball or use a machine learning algorithm. At first, I would have saved it simply and simply used the threshold values โ€‹โ€‹obtained after studying some images.

Hope this helps.

+5
source

Source: https://habr.com/ru/post/1200973/


All Articles