4

I am trying to detect a ball in an filtered image. In this image I've already removed the stuff that can't be part of the object. Of course I tried the HoughCircle function, but I did not get the expected output. Either it didn't find the ball or there were too many circles detected. The problem is that the ball isn't completly round.

Screenshots:

enter image description here

I had the idea that it could work, if I identify single objects, calculate their center and check whether the radius is about the same in different directions. But it would be nice if it detect the ball also if he isn't completely visible. And with that method I can't detect semi-circles or something like that.

EDIT: These images are from a video stream (real time).

What other method could I try?

enter image description here

Kite
  • 651
  • 6
  • 16
  • I've already looked at "http://stackoverflow.com/questions/20698613/detect-semi-circle-in-opencv", but this solution don't work well in my case... – Kite Aug 23 '14 at 13:50
  • If you can get enough training images a cascade classifier has a good chance of working for this application. – Bull Aug 23 '14 at 14:28
  • Thank you. There are definitely enough images, because these images are from a video stream (I've added this information). I've never worked with a cascade classifier, but I will try to deal with it. – Kite Aug 24 '14 at 09:33

1 Answers1

5

Looks like you've used difference imaging or something similar to obtain the images you have..? Instead of looking for circles, look for a more generic loop. Suggestions:

  • Separate all connected components.
  • For every connected component -
  • Walk around the contour and collect all contour pixels in a list
  • Suggestion 1: Use least squares to fit an ellipse to the contour points
  • Suggestion 2: Study the curvature of every contour pixel and check if it fits a circle or ellipse. This check may be done by computing a histogram of edge orientations for the contour pixels, or by checking the gradients of orienations from contour pixel to contour pixel. In the second case, for a circle or ellipse, the gradients should be almost uniform (ask me if this isn't very clear).
  • Apply constraints on perimeter, area, lengths of major and minor axes, etc. of the ellipse or loop. Collect these properties as features.
  • You can either use hard-coded heuristics/thresholds to classify a set of features as ball/non-ball, or use a machine learning algorithm. I would first keep it simple and simply use thresholds obtained after studying some images.

Hope this helps.

Zaphod
  • 1,927
  • 11
  • 13
  • 2
    In addition to suggestion 2, you can simply check the circularity of a contour by the following formula: **circularity = (4*PI*A)/P^2**, where _A_ is the area surrounded by the contour and _P_ is the perimeter of the contour. A circle has a circularity of 1. – Dennis Aug 23 '14 at 19:07
  • Thanks for your quick response. I'll try out these helpful suggestions. Have you any idea, whether this will be fast enough for a real time video stream ? – Kite Aug 24 '14 at 09:45
  • It will mostly depend on your implementation, but in the past I have done ellipse detection on HD images at around 25ms per frame. So I'll say yes. – Zaphod Aug 24 '14 at 11:11