justmyfreak
justmyfreak

Reputation: 1270

Counting object on image algorithm

I got school task again. This time, my teacher gave me task to create algorithm to count how many ducks on picture.

The picture is similar to this one:

I think I should use pattern recognition for searching how many ducks on it. But I don't know which pattern match for each duck.

Upvotes: 5

Views: 4134

Answers (3)

Liudvikas Bukys
Liudvikas Bukys

Reputation: 5870

Here's one way:

Hough transform for circles:

  • Initialize an accumulator array indexed by (x,y,radius)
  • For each pixel:
    • calculate an edge (e.g. Sobel operator will provide both magnitude and direction), if magnitude exceeds some threshold then:
      • increment every accumulator for which this edge could possibly lend evidence (only the (x,y) in the direction of the edge, only radii between min_duck_radius and max_duck_radius)
  • Now smooth and threshold the accumulator array, and the coordinates of highest accumulators show you where the heads are. The threshold may leap out at you if you histogram the values in the accumulators (there may be a clear difference between "lots of evidence" and "noise").

So that's very terse, but it can get you started.

Upvotes: 2

Alceu Costa
Alceu Costa

Reputation: 9899

I think that you can solve this problem by segmenting the ducks' beaks and counting the number of connected components in the binary image.

To segment the ducks' beaks, first convert the image to HSV color space and then perform a binarization using the hue component. Note that the ducks' beaks hue are different from other parts of the image.

Upvotes: 6

penelope
penelope

Reputation: 8418

It might be just because I'm working with SIFT right now, but to me it looks like it could be good for your problem.

It is an algorithm that matches the same object on two different pictures, where the objects can have different orientations, scales and be viewed from different perspectives on the two pictures. It can also work when an object is partially hidden (as your ducks are) by another object.

I'd suggest finding a good clear picture of a rubber ducky ( :D ) and then use some SIFT implementation (VLFeat - C library with SIFT but no visualization, SIFT++ - based on VLFeat, but in C++ , Rob Hess in C with OpenCV...).

You should bear in mind that matching with SIFT (and anything else) is not perfect - so you might not get the exact number of rubber duckies in the picture.

Upvotes: 2

Related Questions