def __init__(self,prescale=0.25,weights=WEIGHTS,default=True): ''' Initialize the detector with default parameters. ''' # Look for very small faces self.fd = cd.CascadeDetector(min_size=(30,30)) # Look for larger heads and shoulders self.hd = cd.CascadeDetector(cd.UPPERBODY_MCS_CASCADE,min_size=(60,60)) # Scale self.prescale = prescale # Returns a detection that can be used as a default if no other detections are avalible self.default = default # This regression will provide a quality score for the detector. self.quality = pv.LogisticRegression() self.quality.params = weights
def facedetect(): faceDetector = cd.CascadeDetector() eyeDetector = ed.FilterEyeLocator() im = pv.Image("testImage.jpg", bw_annotate=True) faces = faceDetector(im) eyes = eyeDetector(im, faces) for face, eye1, eye2 in eyes: im.annotatePolygon(face.asPolygon(), width=4) im.annotatePoints([eye1, eye2]) im.show(delay=0)
def pyvision_detect_faces(image): global face_detect if face_detect is None: face_detect = cd.CascadeDetector() # print "DETECTING FACES" if not hasattr(image, "asOpenCV"): if hasattr(image, "shape"): # numpy ndarray, assuming it comes from cv2 image = cvu.cv2ndarray_to_iplimage(image) image = pv.Image(image, bw_annotate=True) faces = face_detect(image) # print "DETECTING FACES DONE." return faces
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 )
import pyvision as pv import pyvision.face.CascadeDetector as cd if __name__ == '__main__': detector = cd.CascadeDetector() cam = pv.Webcam() for frame in cam: rects = detector(frame) for rect in rects: frame.annotateRect(rect) frame.show(delay=30)