numpy - Hand gesture recognition (PCA) - Python -


this question has answer here:

i trying make hand gesture recognition principal component analysis (pca) using python. following steps in tutorial: http://onionesquereality.wordpress.com/2009/02/11/face-recognition-using-eigenfaces-and-distance-classifiers-a-tutorial/

here code:

import os pil import image import numpy np import glob import numpy.linalg linalg   #step 1: put training images 2d array filenames = glob.glob('c:\\users\\karim\\desktop\\training & test images\\new folder\\training/*.png') filenames.sort() img = [image.open(fn).convert('l').resize((90, 90)) fn in filenames] images = np.asarray([np.array(im).flatten() im in img])   #step 2: find mean image , mean-shifted input images mean_image = images.mean(axis=0) shifted_images = images - mean_image   #step 3: covariance c = np.asmatrix(shifted_images) * np.asmatrix(shifted_images.t)   #step 4: sorted eigenvalues , eigenvectors eigenvalues,eigenvectors = linalg.eig(c) idx = np.argsort(-eigenvalues) eigenvalues = eigenvalues[idx] eigenvectors = eigenvectors[:, idx]   #step 6: finding weights w = eigenvectors.t * np.asmatrix(shifted_images)   w = np.asarray(w)   #step 7: input (test) image input_image = image.open('c:\\users\\karim\\desktop\\training & test images\\new folder\\test\\31.png').convert('l').resize((90, 90)) input_image = np.asarray(input_image).flatten()   #step 8: normalized image, covariance, eigenvalues , eigenvectors input image shifted_in = input_image - mean_image c = np.cov(input_image) cmat = c.reshape(1,1) eigenvalues_in, eigenvectors_in = linalg.eig(cmat)   #step 9: fing weights of input image w_in = eigenvectors_in.t * np.asmatrix(shifted_in)  w_in = np.asarray(w_in)   #step 10: euclidean distance df = np.asarray(w - w_in)                # difference between images dst = np.sqrt(np.sum(df**2, axis=1))     # euclidean distances idx = np.argmin(dst)                     # index of smallest value in 'dst' should equal index of simillar image in 'images' print idx 

the detected image should nearest training images test image, result different one, although each test image there 10 similar images in training image.

anyone can help?

pca on raw image bitmaps poor algorithm face recognition. put bluntly, don't expect work using real images of people's faces. it's useful learning tool, that's it.

try testing algorithm extremely simple images -- think white images black shapes in different places. pca should able well. if works on those, congrats, wrote correctly. move more sophisticated algorithm.

or download standard academic dataset of face images has been shown in research work pca. small issues alignment , color critical such simple algorithm.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -