def detect_and_handle_faces(img, recognizer=None):
    faces = face_detect_on_photo(img)
    for face in faces:
        face = normalize_face_for_save(face)
        face = np.asarray(face)
        if face_is_blurry(face):
            continue
        cv2.imshow("Face", face)
        if recognizer is not None:
            [label_id, confidence] = recognizer.predict(face)
            person = get_person_from_label(label_id)
            print "Predicting %s with %s confidence" % (person, confidence)
        else:
            label_id = None
        save_face(face, label_id)
def detect_and_handle_faces(img, sonos_device=None, recognizer=None):
    faces = face_detect_on_photo(img)
    for face in faces:
        face = normalize_face_for_save(face)
        face = np.asarray(face)
        cv2.imshow("Face", face)
        if recognizer is not None:
            [label_id, confidence] = recognizer.predict(face)
            if confidence <= CONFIDENCE_THRESHOLD:
                person = get_person_from_label(label_id)
                print "Predicting %s with %s confidence" % (person, confidence)
                if sonos_device is not None:
                    try_to_play_music(label_id, sonos_device)
        else:
            label_id = None
        save_face(face, label_id)