Example #1
0
    def test_3_EigenFaceCovariance(self):
        '''Eigenfaces: Stddev of non whitened training vectors..............'''
        ilog = None
        if 'ilog' in globals().keys():
            ilog = globals()['ilog']

        ef = self.trainScraps(whiten=False)

        ssdb = ScrapShotsDatabase()
        keys = list(ssdb.keys())
        keys.sort()

        matrix = []
        for face_id in keys:
            face = ssdb[face_id]
            if face.person_id not in self.scraps_training:
                continue

            fr = ef.getFaceRecord(face.image, face.face_rect, face.left_eye,
                                  face.right_eye)
            matrix.append(fr.eigenfaces_feature)

        matrix = np.array(matrix)

        vals = matrix.std(axis=0).flatten()
        self.assertEquals(len(vals), 53)
        self.assert_(np.abs(vals - 1.0).max() > 0.0001)
        for i in range(len(vals)):
            # Make sure that the eigenvalues are an estimate of the variance
            self.assertAlmostEquals(vals[i],
                                    np.sqrt(ef.eigenvalues[i]),
                                    places=4)
Example #2
0
    def test_2_EigenFaceWhiten(self):
        '''Eigenfaces: Stddev of whitened training vectors == 1.0...........'''
        ilog = None
        if 'ilog' in globals().keys():
            ilog = globals()['ilog']

        ef = self.trainScraps()

        # TODO: Double check.  Remove these later

        ssdb = ScrapShotsDatabase()
        keys = list(ssdb.keys())
        keys.sort()

        matrix = []
        for face_id in keys:
            #print "Processing:",face_id
            face = ssdb[face_id]
            if face.person_id not in self.scraps_training:
                continue

            fr = ef.getFaceRecord(face.image, face.face_rect, face.left_eye,
                                  face.right_eye)
            matrix.append(fr.eigenfaces_feature)

        #print matrix
        matrix = np.array(matrix)

        vals = matrix.std(axis=0)
        self.assertEquals(len(vals), 53)
        self.assert_(np.abs(vals - 1.0).max() < 0.0001)
Example #3
0
    def test_3_EigenFaceCovariance(self):
        '''Eigenfaces: Stddev of non whitened training vectors..............'''
        ilog = None
        if 'ilog' in globals().keys():
            ilog = globals()['ilog']
        
        ef = self.trainScraps(whiten=False)
        
        ssdb = ScrapShotsDatabase()
        keys = list(ssdb.keys())
        keys.sort()
        
        matrix = []
        for face_id in keys:
            face = ssdb[face_id]
            if face.person_id not in self.scraps_training:
                continue

            fr = ef.getFaceRecord(face.image,face.face_rect,face.left_eye,face.right_eye)
            matrix.append(fr.eigenfaces_feature)
        
        matrix = np.array(matrix)
        
        vals = matrix.std(axis=0).flatten()
        self.assertEquals(len(vals),53)
        self.assert_(np.abs(vals-1.0).max()>0.0001)
        for i in range(len(vals)):
            # Make sure that the eigenvalues are an estimate of the variance
            self.assertAlmostEquals(vals[i],np.sqrt(ef.eigenvalues[i]),places=4)
Example #4
0
    def test_2_EigenFaceWhiten(self):
        '''Eigenfaces: Stddev of whitened training vectors == 1.0...........'''
        ilog = None
        if 'ilog' in globals().keys():
            ilog = globals()['ilog']
        
        ef = self.trainScraps()
        
        # TODO: Double check.  Remove these later
        
        ssdb = ScrapShotsDatabase()
        keys = list(ssdb.keys())
        keys.sort()
        
        matrix = []
        for face_id in keys:
            #print "Processing:",face_id
            face = ssdb[face_id]
            if face.person_id not in self.scraps_training:
                continue

            fr = ef.getFaceRecord(face.image,face.face_rect,face.left_eye,face.right_eye)
            matrix.append(fr.eigenfaces_feature)
        
        #print matrix
        matrix = np.array(matrix)
        
        vals = matrix.std(axis=0)
        self.assertEquals(len(vals),53)
        self.assert_(np.abs(vals-1.0).max()<0.0001)
Example #5
0
    def test_ASEFEyeLocalization(self):
        '''FilterEyeLocator: Scrapshots Both10 rate == 0.4800...............'''
        ilog = None
        if 'ilog' in list(globals().keys()):
            ilog = globals()['ilog']
            
        # Load a face database
        ssdb = ScrapShotsDatabase()
                
        # Create a face detector 
        face_detector = CascadeDetector()

        # Create an eye locator
        eye_locator = FilterEyeLocator()
        
        # Create an eye detection test
        edt = EyeDetectionTest(name='asef_scraps')

        #print "Testing..."
        for face_id in list(ssdb.keys())[:25]:
            face = ssdb[face_id]
            im = face.image
            
            dist = face.left_eye.l2(face.right_eye)
            dist = np.ceil(0.1*dist)
            im.annotateCircle(face.left_eye,radius=dist,color='white')
            im.annotateCircle(face.right_eye,radius=dist,color='white')

            # Detect the faces
            faces = face_detector.detect(im)
                            
            # Detect the eyes
            pred_eyes = eye_locator(im,faces)
            for rect,leye,reye in pred_eyes:
                im.annotateRect(rect)
                im.annotateCircle(leye,radius=1,color='red')
                im.annotateCircle(reye,radius=1,color='red')
                
            
            truth_eyes = [[face.left_eye,face.right_eye]]
            
            pred_eyes = [ [leye,reye] for rect,leye,reye in pred_eyes]
            
            # Add to eye detection test
            edt.addSample(truth_eyes, pred_eyes, im=im, annotate=True)
            if ilog != None:
                ilog.log(im,label='test_ASEFEyeLocalization')
                
        edt.createSummary()
        
        # Very poor accuracy on the scrapshots database
        self.assertAlmostEqual( edt.face_rate ,   1.0000, places = 3 )
        self.assertAlmostEqual( edt.both25_rate , 0.8800, places = 3 )
        self.assertAlmostEqual( edt.both10_rate , 0.5200, places = 3 )
        self.assertAlmostEqual( edt.both05_rate , 0.2800, places = 3 )
Example #6
0
    def test_ASEFEyeLocalization(self):
        '''FilterEyeLocator: Scrapshots Both10 rate == 0.4800...............'''
        ilog = None
        if 'ilog' in globals().keys():
            ilog = globals()['ilog']

        # Load a face database
        ssdb = ScrapShotsDatabase()

        # Create a face detector
        face_detector = CascadeDetector()

        # Create an eye locator
        eye_locator = FilterEyeLocator()

        # Create an eye detection test
        edt = EyeDetectionTest(name='asef_scraps')

        #print "Testing..."
        for face_id in ssdb.keys()[:25]:
            face = ssdb[face_id]
            im = face.image

            dist = face.left_eye.l2(face.right_eye)
            dist = np.ceil(0.1 * dist)
            im.annotateCircle(face.left_eye, radius=dist, color='white')
            im.annotateCircle(face.right_eye, radius=dist, color='white')

            # Detect the faces
            faces = face_detector.detect(im)

            # Detect the eyes
            pred_eyes = eye_locator(im, faces)
            for rect, leye, reye in pred_eyes:
                im.annotateRect(rect)
                im.annotateCircle(leye, radius=1, color='red')
                im.annotateCircle(reye, radius=1, color='red')

            truth_eyes = [[face.left_eye, face.right_eye]]

            pred_eyes = [[leye, reye] for rect, leye, reye in pred_eyes]

            # Add to eye detection test
            edt.addSample(truth_eyes, pred_eyes, im=im, annotate=True)
            if ilog != None:
                ilog.log(im, label='test_ASEFEyeLocalization')

        edt.createSummary()

        # Very poor accuracy on the scrapshots database
        self.assertAlmostEqual(edt.face_rate, 1.0000, places=3)
        self.assertAlmostEqual(edt.both25_rate, 0.8800, places=3)
        self.assertAlmostEqual(edt.both10_rate, 0.5200, places=3)
        self.assertAlmostEqual(edt.both05_rate, 0.2800, places=3)
    def test_ASEFEyeLocalization(self):
        '''
        This trains the FaceFinder on the scraps database.
        '''
        # Load a face database
        ssdb = ScrapShotsDatabase()
                
        # Create a face detector 
        face_detector = cd.CascadeDetector()

        # Create an eye locator
        eye_locator = FilterEyeLocator()
        
        # Create an eye detection test
        edt = EyeDetectionTest(name='asef_scraps')

        #print "Testing..."
        for face_id in ssdb.keys():
            face = ssdb[face_id]
            im = face.image

            # Detect the faces
            faces = face_detector.detect(im)
            
            # Detect the eyes
            pred_eyes = eye_locator(im,faces)
            
            truth_eyes = [[face.left_eye,face.right_eye]]
            pred_eyes = [ [leye,reye] for _,leye,reye in pred_eyes]
            
            # Add to eye detection test
            edt.addSample(truth_eyes, pred_eyes, im=im, annotate=False)
        
        edt.createSummary()
        self.assertAlmostEqual( edt.face_rate ,   0.97109826589595372, places = 3 ) # Updated numbers for OpenCV 2.0
        self.assertAlmostEqual( edt.both25_rate , 0.82658959537572252, places = 3 )
        self.assertAlmostEqual( edt.both10_rate , 0.47976878612716761, places = 3 )
        self.assertAlmostEqual( edt.both05_rate , 0.30635838150289019, places = 3 )

        
    
    
        
Example #8
0
    def test_ASEFEyeLocalization(self):
        '''
        This trains the FaceFinder on the scraps database.
        '''
        # Load a face database
        ssdb = ScrapShotsDatabase()
                
        # Create a face detector 
        face_detector = cd.CascadeDetector()

        # Create an eye locator
        eye_locator = FilterEyeLocator()
        
        # Create an eye detection test
        edt = EyeDetectionTest(name='asef_scraps')

        #print "Testing..."
        for face_id in ssdb.keys():
            face = ssdb[face_id]
            im = face.image

            # Detect the faces
            faces = face_detector.detect(im)
            
            # Detect the eyes
            pred_eyes = eye_locator(im,faces)
            
            truth_eyes = [[face.left_eye,face.right_eye]]
            pred_eyes = [ [leye,reye] for _,leye,reye in pred_eyes]
            
            # Add to eye detection test
            edt.addSample(truth_eyes, pred_eyes, im=im, annotate=False)
        
        edt.createSummary()
        self.assertAlmostEqual( edt.face_rate ,   0.97109826589595372, delta = 0.01 ) # Updated numbers for OpenCV 2.0
        self.assertAlmostEqual( edt.both25_rate , 0.82658959537572252, delta = 0.01 )
        self.assertAlmostEqual( edt.both10_rate , 0.47976878612716761, delta = 0.01 )
        self.assertAlmostEqual( edt.both05_rate , 0.30635838150289019, delta = 0.01 )

        
    
    
        
Example #9
0
    def trainScraps(self,whiten=True,ilog=None):
        # Load a face database
        ssdb = ScrapShotsDatabase()
        keys = list(ssdb.keys())
        keys.sort()
        
        # Create an eigenfaces instance
        ef = Eigenfaces(whiten=whiten)

        for face_id in keys:
            #print "Processing:",face_id
            face = ssdb[face_id]
            if face.person_id not in self.scraps_training:
                continue

            ef.addTraining(face.image,face.face_rect,face.left_eye,face.right_eye,ilog=ilog)
        
        ef.train(ilog=ilog)
        return ef
Example #10
0
    def test_5_EigenfacesScrapShotsIdentNonWhitened(self):
        '''Eigenfaces: Scrapshot nonwhitened  rate == 0.46 at FAR == 1/10...'''
        ilog = None
        if 'ilog' in globals().keys():
            ilog = globals()['ilog']

        ef = self.trainScraps(whiten=False)

        ssdb = ScrapShotsDatabase()
        keys = list(ssdb.keys())
        keys.sort()

        face_ids = []
        face_records = []

        for face_id in keys:
            face = ssdb[face_id]
            if face.person_id not in self.scraps_testing:
                continue

            fr = ef.getFaceRecord(face.image, face.face_rect, face.left_eye,
                                  face.right_eye)
            face_records.append(fr)
            face_ids.append(face_id)

        sim_matrix = ef.similarityMatrix(face_records, face_records)

        match_scores = []
        nonmatch_scores = []
        for i in range(1, len(face_ids)):
            for j in range(i + 1, len(face_ids)):
                i_id = face_ids[i]
                j_id = face_ids[j]
                if i_id[:5] == j_id[:5]:
                    match_scores.append(sim_matrix[i, j])
                else:
                    nonmatch_scores.append(sim_matrix[i, j])

        roc = ROC(match_scores, nonmatch_scores, is_distance=False)
        roc_point = roc.getFAR(1.0 / 10.0)

        self.assertAlmostEqual(roc_point.frr, 0.53714285714285714, places=2)
Example #11
0
    def test_5_EigenfacesScrapShotsIdentNonWhitened(self):
        '''Eigenfaces: Scrapshot nonwhitened  rate == 0.46 at FAR == 1/10...'''
        ilog = None
        if 'ilog' in globals().keys():
            ilog = globals()['ilog']
        
        ef = self.trainScraps(whiten=False)
        
        ssdb = ScrapShotsDatabase()
        keys = list(ssdb.keys())
        keys.sort()
        
        face_ids = []
        face_records = []
        
        for face_id in keys:
            face = ssdb[face_id]
            if face.person_id not in self.scraps_testing:
                continue

            fr = ef.getFaceRecord(face.image,face.face_rect,face.left_eye,face.right_eye)
            face_records.append(fr)
            face_ids.append(face_id)
            
        sim_matrix = ef.similarityMatrix(face_records,face_records)
        
        match_scores = []
        nonmatch_scores = []
        for i in range(1,len(face_ids)):
            for j in range(i+1,len(face_ids)):
                i_id = face_ids[i]
                j_id = face_ids[j]
                if i_id[:5] == j_id[:5]:
                    match_scores.append(sim_matrix[i,j])
                else:
                    nonmatch_scores.append(sim_matrix[i,j])
        
        roc = ROC(match_scores,nonmatch_scores,is_distance=False)
        roc_point = roc.getFAR(1.0/10.0)
        
        self.assertAlmostEqual(roc_point.frr,0.53714285714285714,places=2)
Example #12
0
    def trainScraps(self, whiten=True, ilog=None):
        # Load a face database
        ssdb = ScrapShotsDatabase()
        keys = list(ssdb.keys())
        keys.sort()

        # Create an eigenfaces instance
        ef = Eigenfaces(whiten=whiten)

        for face_id in keys:
            #print "Processing:",face_id
            face = ssdb[face_id]
            if face.person_id not in self.scraps_training:
                continue

            ef.addTraining(face.image,
                           face.face_rect,
                           face.left_eye,
                           face.right_eye,
                           ilog=ilog)

        ef.train(ilog=ilog)
        return ef