Search code examples
c++opencvimage-processingcomputer-visionobject-detection

Differentiate between appending objects with similar color


I am trying to detect each ball, count how many there are, and get their location. I am currently using Canny Edge Detection for that which works pretty well if the balls don't touch each other:

Canny Detection with balls not touching each other

The problem I have is that if the balls are touching, it is not possible to differentiate between them anymore and they are treated as one object:

Canny Detection with balls touching each other

I tried to use HoughCircles, but found that this only works well with actual circles, not distorted ones.

So how would I go about finding a solution? Is there any algorithm that fits better for this problem, or can I somehow work out the individual circles in each contour?


Solution

  • What you could try is to filter the frame on red and green, so you get the contours of your balls. Then use a watershed algorithm to separate the contours.

    Watershed example: https://docs.opencv.org/4.x/d2/dbd/tutorial_distance_transform.html