2

I'm trying to write a script in python to detect and count objects inside an image, but I'm failing miserably.

It is the first time I get interested and try something by means of computer vision. I have tried using cv2 module (open cv) following the tutorials about Feature Matching and Template Matching present here. I have also tried with scikit-image but I cannot achieve a good result either. I have also thought about finding contours and then making 2d-curve matching.

Let me explain a little bit more the problem. I have a set of icons which are the ones composing an big image. The composition of this image or scene is done by a plain background or an transparent one, and a number of images from the iconset. These images from the iconset can undergo basically 3 basic transformations: scale, rotation and translation. They can also be overlapped.

An quick example by means of Android version icons.

The output of the desired script will be something like:

C -> 1

D -> 1

E -> 1

F -> 1

G -> 1

H -> 2

I -> 3

J -> 0

I'm going to try now with Dlib and see if I can achieve something with machine learning algorithms. I think that I'm trying to solve my problem by something much more complex that actually needed. Any advice on how to do it will be great, I'm also open to any library for python.

PS: sorry for not publishing here the images but I do not have enough reputation yet.

Sabo-Tabby
  • 63
  • 1
  • 6

1 Answers1

1

There many techniques that you can try. But if you really want to make something quick and easy, try to manipulate your image set such that each category has clearly distinctive and unique colours. Thus you can make some decisions of object presence by looking for its colour, or even better count number of contours of specific colour.

The pseudo-code:

  1. pre-process image -- (normalize,threshold only targeted colors by using backprojections function)
  2. findContours
  3. for each contour
    1. check if it is valid "feature" contour -- you can later further enhance your program by filtering some noisy regions
    2. estimate most probable category it belongs to.

This should also give you pretty good performance speed. Otherwise you have to make some assumptions on icons' scale, rotation, occlusion/overlapping situations.

ivan_a
  • 613
  • 5
  • 12
  • 1
    Thanks I will try this solution ASAP. Anyhow, I have achieved pretty good results thanks to SVM tools for object detection available at [dlib library](http://dlib.net/). – Sabo-Tabby Oct 22 '14 at 00:03