Package pyvision :: Package gui :: Module SimpleLiveDemo
[hide private]
[frames] | no frames]

Source Code for Module pyvision.gui.SimpleLiveDemo

 1  ''' 
 2  This file provides a basic framework for a live demo.  In this case the  
 3  demo is for face and eye detection. 
 4   
 5  Copyright David S. Bolme 
 6   
 7  Created on Jul 9, 2011 
 8   
 9  @author: bolme 
10  ''' 
11  import pyvision as pv 
12  import cv 
13  from pyvision.face.CascadeDetector import CascadeDetector 
14  from pyvision.face.FilterEyeLocator import FilterEyeLocator 
15   
16 -def mouseCallback(event, x, y, flags, param):
17 if event in [cv.CV_EVENT_LBUTTONDOWN,cv.CV_EVENT_LBUTTONUP]: 18 print "Mouse Event:",event,x,y
19 20 if __name__ == '__main__': 21 22 # Setup the webcam 23 webcam = pv.Webcam() 24 25 # Setup the face and eye detectors 26 cd = CascadeDetector(min_size=(100,100)) 27 el = FilterEyeLocator() 28 29 # Setup the mouse callback to handle mause events (optional) 30 cv.NamedWindow("PyVision Live Demo") 31 cv.SetMouseCallback("PyVision Live Demo", mouseCallback) 32 33 while True: 34 # Grab a frame from the webcam 35 frame = webcam.query() 36 37 # Run Face and Eye Detection 38 rects = cd(frame) 39 eyes = el(frame,rects) 40 41 # Annotate the result 42 for rect,leye,reye in eyes: 43 frame.annotateThickRect(rect, 'green', width=3) 44 frame.annotatePoint(leye, color='green') 45 frame.annotatePoint(reye, color='green') 46 47 # Annotate instructions 48 frame.annotateLabel(pv.Point(10,10), "Press 'q' to quit.") 49 50 # Show the frame (uses opencv highgui) 51 key_press = frame.show("PyVision Live Demo") 52 53 # Handle key press events. 54 if key_press == ord('q'): 55 break 56