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

Source Code for Module pyvision.face.testsuite

  1  ''' 
  2  Created on Jul 1, 2009 
  3   
  4  This module contains tests for the face recognition algorithms. 
  5   
  6  @author: bolme 
  7  ''' 
  8   
  9  import unittest 
 10   
 11  import pyvision as pv 
 12  import numpy as np 
 13  pv.disableCommercialUseWarnings() 
 14   
 15  from pyvision.analysis.FaceAnalysis.FaceDatabase     import ScrapShotsDatabase 
 16  from pyvision.analysis.FaceAnalysis.EyeDetectionTest import EyeDetectionTest 
 17  from pyvision.face.CascadeDetector                   import CascadeDetector 
 18  from pyvision.face.FilterEyeLocator                  import FilterEyeLocator 
 19   
 20  #from pyvision.analysis.roc                           import ROC 
 21   
22 -class TestFilterEyeLocator(unittest.TestCase):
23
24 - def test_ASEFEyeLocalization(self):
25 '''FilterEyeLocator: Scrapshots Both10 rate == 0.4800...............''' 26 ilog = None 27 if 'ilog' in globals().keys(): 28 ilog = globals()['ilog'] 29 30 # Load a face database 31 ssdb = ScrapShotsDatabase() 32 33 # Create a face detector 34 face_detector = CascadeDetector() 35 36 # Create an eye locator 37 eye_locator = FilterEyeLocator() 38 39 # Create an eye detection test 40 edt = EyeDetectionTest(name='asef_scraps') 41 42 #print "Testing..." 43 for face_id in ssdb.keys()[:25]: 44 face = ssdb[face_id] 45 im = face.image 46 47 dist = face.left_eye.l2(face.right_eye) 48 dist = np.ceil(0.1*dist) 49 im.annotateCircle(face.left_eye,radius=dist,color='white') 50 im.annotateCircle(face.right_eye,radius=dist,color='white') 51 52 # Detect the faces 53 faces = face_detector.detect(im) 54 55 # Detect the eyes 56 pred_eyes = eye_locator(im,faces) 57 for rect,leye,reye in pred_eyes: 58 im.annotateRect(rect) 59 im.annotateCircle(leye,radius=1,color='red') 60 im.annotateCircle(reye,radius=1,color='red') 61 62 63 truth_eyes = [[face.left_eye,face.right_eye]] 64 65 pred_eyes = [ [leye,reye] for rect,leye,reye in pred_eyes] 66 67 # Add to eye detection test 68 edt.addSample(truth_eyes, pred_eyes, im=im, annotate=True) 69 if ilog != None: 70 ilog.log(im,label='test_ASEFEyeLocalization') 71 72 edt.createSummary() 73 74 # Very poor accuracy on the scrapshots database 75 self.assertAlmostEqual( edt.face_rate , 1.0000, places = 3 ) 76 self.assertAlmostEqual( edt.both25_rate , 0.8800, places = 3 ) 77 self.assertAlmostEqual( edt.both10_rate , 0.5200, places = 3 ) 78 self.assertAlmostEqual( edt.both05_rate , 0.2800, places = 3 )
79 80 81 82
83 -def test():
84 '''Run the face test suite.''' 85 pv.disableCommercialUseWarnings() 86 87 fel_suite = unittest.TestLoader().loadTestsFromTestCase(TestFilterEyeLocator) 88 89 90 91 test_suites = [ 92 fel_suite, 93 ] 94 95 pyvision_suite = unittest.TestSuite(test_suites) 96 97 unittest.TextTestRunner(verbosity=2).run(pyvision_suite)
98 99 100 if __name__ == '__main__': 101 # By default run the test suite 102 #ilog = pv.ImageLog() 103 test() 104 #ilog.show() 105