Exemplo n.º 1
0
def recognize_face(recognizer, image, face_cascade, eye_cascade, face_size, threshold):
    found_faces = []

    gray, faces = detect_faces(image, face_cascade, eye_cascade, return_gray=1)

    # If faces are found, try to recognize them
    for ((x, y, w, h), eyedim)  in faces:
        label, confidence = recognizer.predict(cv2.resize(level_face(gray, ((x, y, w, h), eyedim)), face_size))
        if confidence < threshold:
            found_faces.append((label, confidence, (x, y, w, h)))

    return found_faces
Exemplo n.º 2
0
def _extract_faces(a_dir, folder, do_level_face=False):
    faceCascade = cv2.CascadeClassifier(config.FACE_CASCADE_FILE)
    eyeCascade = cv2.CascadeClassifier(config.EYE_CASCADE_FILE)

    the_path = join(a_dir, folder)
    result = []

    for img in [f for f in os.listdir(the_path) if _supported_img(f)]:
        img_path = join(the_path, img)
        image, faces = detect_faces(cv2.imread(img_path), faceCascade, eyeCascade, True)
        if len(faces) == 0:
            print("No face found in " + img_path)
        for ((x, y, w, h), eyedim) in faces:
            if not do_level_face:
                result.append(image[y:y+h, x:x+w])
            else:
                result.append(level_face(image, ((x, y, w, h), eyedim)))
                #result.append(image[y:y+h, x:x+w])
    return result