views:

1760

answers:

4

hi, what I want to do is a image recognition for a simple app:

  1. given image (500 x 500) pxs ( 1 color background )
  2. the image will have only 1 geometric figure (triangle or square or smaleyface :) ) of (50x50) pxs.
  3. python will do the recognition of the figure and display what geometric figure is.

any links? any hints? any API? thxs :)

A: 

If you know the statespace of your data, you can use Principal Component Analysis. With PCA all of the objects must be posed (in the center of the screen). PCA will not do detection, but it will seperate objects into unique layers in which you can identify as being a triangle, etc. Also note: this is not scale or rotation invariant.

[I can't remember what this technique is called, but its similar to how the postoffice does handwritting rec] If you can handle only non-curved curvfaces, you could do edge detection, and then do sampling at intersections to get an approximation of similarity.

monksy
ok but... the geometric-figure will no be only centered :)
panchicore
+4  A: 

OpenCV has blob analysis tools, it will give you metrics about the shape which you can feed for your favourite pattern recognition algorithm :) Eg. rectangle has 1.0 ratio for area / (height * width), when circle's ratio is about 0.78.

Harriv
+1, nice hint, openCv seems the key, im googling for some practical example...
panchicore
A ratio of 0.78 doesn't always guarente that it will be a circle. There could be many other patterns that would meet the 0.78 value.
monksy
That's true, you should select the set of features which are most meaningful for the set of the objects you're trying to recognize. Fill ratio is only one feature.
Harriv
+6  A: 

A typical python tool chain would be:

As far differentiating the shapes, I would obtain its silhouette by looking at the shape of the background. I would then detect the number of corners using a corner detection algorithm (e.g. Harris). A triangle has 3 corners, a square 4, and a smiley none. Here's a python implementation of the Harris corner detection with Scipy.

Edit:

As you mention in the comments, the blog post didn't present the function that produces a gaussian kernel needed in the algorithm. Here's an example of a such a function from the Scipy Cookbook (great resource btw):

def gauss_kern(size, sizey=None):
    """ Returns a normalized 2D gauss kernel array for convolutions """
        size = int(size)
        if not sizey:
            sizey = size
        else:
            sizey = int(sizey)
        x, y = mgrid[-size:size+1, -sizey:sizey+1]
        g = exp(-(x**2/float(size)+y**2/float(sizey)))
        return g / g.sum()
Ivan
+1, nice hint, Scipy seems to be another key, im running the Harris example :)
panchicore
no, i cant run this Harris Example, the code seems to be incomplete :(
panchicore
the line-code: gauss = filtertools.gauss_kernel(3) ... gauss_kernel def does not exists :(
panchicore
+1  A: 

You point the geometric figure is 50x50 px. If size and orientation of the geometric figures are fixed, you have a classic template matching problem, suitable to the correlation method. You can apply the template matching on the original image or on a border detection output.

Otherwise, if size (scale) and/or orientation are arbitrary, Fourier descriptors can be applied. These descriptors are rotation and scale invariants.

All these methods can be coded using OpenCV, NumPy or SciPy.

TH