Package pyvision :: Package face :: Module FaceRecognizer
[hide private]
[frames] | no frames]

Source Code for Module pyvision.face.FaceRecognizer

 1  # PyVision License 
 2  # 
 3  # Copyright (c) 2006-2008 David S. Bolme 
 4  # All rights reserved. 
 5  # 
 6  # Redistribution and use in source and binary forms, with or without 
 7  # modification, are permitted provided that the following conditions 
 8  # are met: 
 9  #  
10  # 1. Redistributions of source code must retain the above copyright 
11  # notice, this list of conditions and the following disclaimer. 
12  #  
13  # 2. Redistributions in binary form must reproduce the above copyright 
14  # notice, this list of conditions and the following disclaimer in the 
15  # documentation and/or other materials provided with the distribution. 
16  #  
17  # 3. Neither name of copyright holders nor the names of its contributors 
18  # may be used to endorse or promote products derived from this software 
19  # without specific prior written permission. 
20  #  
21  #  
22  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
23  # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
24  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
25  # A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR 
26  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
27  # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
28  # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
29  # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
30  # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
31  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
32  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
33   
34 -class FaceRecognizer:
35 ''' Base class for a face recognition algorithm. Output is a similarity score. '''
36 - def __init__(self):
37 self.training_data=[]
38
39 - def getTrainingMatches(self):
40 ''' 41 Returns a list of all pairs of images in the training set that 42 are of the same person. 43 ''' 44 matches = [] 45 for i in range(len(self.training_data)): 46 for j in range(i+1,len(self.training_data)): 47 if i == j: 48 continue 49 if self.training_data[i][3] == self.training_data[j][3]: 50 matches.append([self.training_data[i],self.training_data[j]]) 51 return matches
52 53
54 - def getTrainingNonMatches(self):
55 ''' 56 Returns a list of all pairs in the training images that are of 57 different people. 58 ''' 59 nonmatches = [] 60 for i in range(len(self.training_data)): 61 for j in range(i+1,len(self.training_data)): 62 if i == j: 63 continue 64 if self.training_data[i][3] != self.training_data[j][3]: 65 nonmatches.append([self.training_data[i],self.training_data[j]]) 66 return nonmatches
67
68 - def addTraining(self,img,rect=None,eyes=None,sub_id=None):
69 '''Adds a training face for the algorithm.''' 70 self.training_data.append([img,rect,eyes,sub_id])
71 72
73 - def distance(self, fr1, fr2):
74 '''Compute the similarity of two faces''' 75 raise NotImplementedError()
76 77
78 - def computeFaceRecord(self,im,rect=None,eyes=None):
79 ''' 80 Given an image and face location, compute a face record. 81 82 @param im: image containing the face 83 @param rect: specifies the location of the face in the image, and is 84 typically defined as a detection rectangle or eye coordinates. 85 86 @returns: data that represents the identity of the face, such as 87 eigen coeffecients for PCA. 88 ''' 89 90 raise NotImplementedError()
91