1  ''' 
  2  Created on Jan 13, 2012 
  3   
  4  @author: bolme 
  5  ''' 
  6  import pyvision as pv 
  7  from pyvision.face.CascadeDetector import CascadeDetector 
  8  import vtm 
  9  import numpy as np 
 10   
 12       
 14          ''' 
 15          This is a change detection task that computes the difference between the current and previous frames. 
 16          ''' 
 17           
 18          vtm.VideoTask.__init__(self, frame_id, args=[("FRAME",frame_id),("FRAME",frame_id-1)]) 
  19           
  34       
 35       
 37       
 39          ''' 
 40          Register for the current and previous frames. 
 41          ''' 
 42          vtm.VideoTask.__init__(self, frame_id, args=[("FRAME",frame_id),("CHANGE_MASK",frame_id)]) 
  43           
  53       
 55      ''' 
 56      This tasks illustrates one way to initialize data in the first frame by  
 57      changing the number of required arguments required by additional frames. 
 58      ''' 
 60          if frame_id == 0: 
 61               
 62              vtm.VideoTask.__init__(self,frame_id,args=[("FRAME",frame_id)]) 
 63          else: 
 64               
 65               
 66               
 67              vtm.VideoTask.__init__(self,frame_id,args=[("FRAME",frame_id),("_FACE_DETECTOR",frame_id-1)]) 
  68       
 69 -    def execute(self,frame,detector=None): 
  70          if detector == None: 
 71              print "Initializing Face Detector." 
 72              detector = CascadeDetector(min_size=(128,128)) 
 73           
 74          faces = detector(frame) 
 75          for rect in faces: 
 76              frame.annotateRect(rect) 
 77           
 78          return [('FACES',self.getFrameId(),faces),("_FACE_DETECTOR",self.getFrameId(),detector)] 
   79   
 80   
 90   
 99   
100  if __name__ == '__main__': 
101       
102      runFaceDetectionExample() 
103