Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 359
justmyfreak Avatar asked Dec 27 '11 12:12

justmyfreak


People also ask

Can a CNN count objects?

Accurately counting objects instances in a given image or video frame is a hard problem to solve in machine learning. A number of solutions have been developed to count people, cars and other objects and none of them is perfect.

How do I count an image in Python?

To count the images one has to make use of computer vision libraries. There are tones of libraries available to achieve the aim of the tutorial. But today in this tutorial, we will be making use of the cvlib library which is very simple, easy, and a high-level library in Python.


3 Answers

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.

like image 200
Alceu Costa Avatar answered Sep 28 '22 00:09

Alceu Costa


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.

like image 25
Liudvikas Bukys Avatar answered Sep 28 '22 01:09

Liudvikas Bukys


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.

like image 37
penelope Avatar answered Sep 28 '22 01:09

penelope