示例#1
0
 def test_face_detector_no_face(self):
     fd.set_classifiers(c1, c2, c3)
     face_box = fd.detect_face(self.test_image_face)
     x1 = face_box.x
     y1 = face_box.y
     x2 = face_box.width + x1
     y2 = face_box.height + y1
     self.assertTrue(face_box is None, "Image does not contain a face!")
示例#2
0
        def test_multiple_faces(self, faces):
            fd.set_classifiers(c1, c2, c3)
            for image in faces:
                index = 0
                face_box = fd.detect_face(image)
                if face_box is not None:
                    x1 = face_box.x
                    y1 = face_box.y
                    x2 = face_box.width + x1
                    y2 = face_box.height + y1

                    self.assertTrue(face_box is not None, "Image %d contains a face between (%d,%d) and (%d,%d)"%(index,x1,y1,x2,y2))
                else:
                    self.assertTrue(face_box is None, "Image %d contains no face!"%s(index))
                index+=1
示例#3
0
import cv2
import argparse
from face_detector import Face_Detector

ap = argparse.ArgumentParser()
ap.add_argument('-f',
                '--face',
                default='cascade/haarcascade_frontalface_default.xml',
                help='path to the face cascade')
ap.add_argument('-i', '--image', required=True, help='path to the image')
args = vars(ap.parse_args())

image = cv2.imread(args['image'])
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.equalizeHist(gray)

fd = Face_Detector(args['face'])
faces = fd.detect(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))

print("%d face(s) detected" % (len(faces)))

for (x, y, w, h) in faces:
    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)

cv2.imshow("Faces", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
示例#4
0
from face_detector import Face_Detector
import imutils

ap = argparse.ArgumentParser()
ap.add_argument('-f',
                '--face',
                default='cascade/haarcascade_frontalface_default.xml',
                help='path to face file')
ap.add_argument('-e',
                '--eyes',
                default='cascade/haarcascade_eye.xml',
                help='path to eyes file')
ap.add_argument('-i', '--video', help='path to optional video file')
args = vars(ap.parse_args())

fd = Face_Detector(args['face'], args['eyes'])

if not args['video']:
    camera = cv2.VideoCapture(0)
else:
    camera = cv2.VideoCapture(args['video'])

if not camera.isOpened:
    print("Failed to load the frames. Exiting ....")

while True:
    ret, frame = camera.read()

    if frame is None and not ret:
        break
示例#5
0
from face_detector import Face_Detector
Face_Detector()