prepare frontal face images to be passed to fisherBased.py - find eyes using HAAR wavelet based detection (Viola-Jones method) - image registration - rotate the image so that line joining the centers of the eyes is horizontal - translate and scale so that all images are in same coordinate system ''' import cv2 import imgUtils import registerImage import os # Assume supplied images have single, frontal face sourcePath = '/Users/pradeep/Desktop/Hackathon/Face Recognition/trainFaces/teen/' filePaths, fileNames = imgUtils.fetchFiles(sourcePath, 'ENDS_WITH', '.jpg') #print filePaths[:5] #print fileNames[:5] # faceCasc = imgUtils.chooseCascade(choice='frontalFace') eyeCasc = imgUtils.chooseCascade( choice='eyeGlasses') # left one ins't always first in returned list sz = 94 offSetH = 0.25 offSetV = 0.25 for path, name in zip(filePaths, fileNames): # Load image in single channle grayscale img = cv2.imread(path, 0)
featureExtractor = feature.Fisherfaces() # Type of distance should match classifier distance = distance.EuclideanDistance() # Type of classifier and criterion for selection classifier = classifier.NearestNeighbor(dist_metric=distance, k=3) # The overall architecture predictor = model.PredictableModel(featureExtractor,classifier) # The training patterns # these patterns were preprocessed via createSample.py # with sz=210, offSetH = 0.25 and offSetV = 0.25 filePaths, fileNames = imgUtils.fetchFiles('/Users/pradeep/Desktop/Hackathon/Face Recognition/trainFaces/ageTraining/', 'ENDS_WITH', 'proto.jpg') # Labels of the raw patterns X = [] y = [] for path, name in zip(filePaths,fileNames): img = cv2.imread(path,0) X.append(img) if name.endswith('tNES_proto.jpg'): y.append(0) # feminie else: y.append(1) # masculine # Train on the samples and corresponding labels
prepare frontal face images to be passed to fisherBased.py - find eyes using HAAR wavelet based detection (Viola-Jones method) - image registration - rotate the image so that line joining the centers of the eyes is horizontal - translate and scale so that all images are in same coordinate system ''' import cv2 import imgUtils import registerImage import os # Assume supplied images have single, frontal face sourcePath = '/Users/pradeep/Desktop/Hackathon/Face Recognition/May2014Training/' filePaths, fileNames = imgUtils.fetchFiles(sourcePath, 'ENDS_WITH', '.jpg') # faceCasc = imgUtils.chooseCascade(choice='frontalFace') eyeCasc = imgUtils.chooseCascade(choice='eyeGlasses') # left one ins't always first in returned list sz = 110 offSetH = 0.25 offSetV = 0.25 for path, name in zip(filePaths,fileNames): # Load image in single channle grayscale img = cv2.imread(path,0) # Register the image with alignment at eyes #img = registerImage.alignAtEyes(eyeCasc, img, name, sz, offSetH,offSetV)