2013-04-19 5 views
2

파이썬을 사용하여 PCA (Principal Component Analysis)에서 손 제스처 인식을 시도하고 있습니다. 나는이 튜토리얼의 단계에 따라 오전 : 여기 http://onionesquereality.wordpress.com/2009/02/11/face-recognition-using-eigenfaces-and-distance-classifiers-a-tutorial/손 제스처 인식 (PCA) - Python

은 내 코드입니다 :

import os 
from PIL import Image 
import numpy as np 
import glob 
import numpy.linalg as linalg 


#Step 1: put training images into a 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)) for fn in filenames] 
images = np.asarray([np.array(im).flatten() for im in img]) 


#Step 2: find the mean image and the 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 and 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: get the normalized image, covariance, eigenvalues and eigenvectors for 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)    # the difference between the images 
dst = np.sqrt(np.sum(df**2, axis=1))  # their euclidean distances 
idx = np.argmin(dst)      # index of the smallest value in 'dst' which should be equal to index of the most simillar image in 'images' 
print idx 

가 감지 된 이미지 테스트 이미지 교육 이미지에서 가장 가까운을해야하지만, 결과는 완전히 다른 하나 , 각 테스트 이미지에는 트레이닝 이미지에 10 개의 유사한 이미지가 있지만

누구든지 도움을받을 수 있습니까?

+0

3 단계에서 'np.cov (shifted_images)'를 사용하지 않는 이유는 무엇입니까? – lvc

답변

2

원시 이미지 비트 맵의 ​​PCA는 얼굴 인식 알고리즘이 좋지 않습니다. 그것을 퉁명스럽게 표현하려면 실제로 사람들의 얼굴 이미지를 사용하여 실제로 작동한다고 기대하지 마십시오. 그것은 학습 도구로서 유용하지만, 그것에 관한 것입니다.

아주 간단한 이미지로 알고리즘을 테스트 해보십시오. 다른 위치에서 검은 색으로 표시된 흰색 이미지를 생각해보십시오. PCA는 그렇게 할 수 있어야합니다. 그것들이 축하 행사에서 작동한다면, 당신은 그것을 정확하게 썼습니다. 그런 다음보다 정교한 알고리즘으로 이동하십시오.

PCA와 함께 연구하기 위해 표시된 얼굴 이미지의 표준 학술 데이터 세트를 다운로드하십시오. 이러한 간단한 알고리즘에서는 정렬 및 색상과 같은 작은 문제가 중요합니다.

+0

손 제스처 인식에 사용하고 있으며 잘못된 결과가 나타납니다 – user2229953

+1

적어도 PCA 대신 LDA를 사용하십시오. 그것은 똑같은 입출력을 가지고 있지만 더 나은 분류를 제공합니다. – Leopd

+0

LDA에 대한 특정 지침서를 제안하나요? – user2229953