def save_faces():
    cv2.namedWindow("Face", cv2.CV_WINDOW_AUTOSIZE)
    while True:
        for cv_array in get_cv_img_from_canon_cam():
            try:
                img = cv.fromarray(cv_array)
            except TypeError:
                print "Warning...got malformed JPEG data"
                continue
            cv2.imshow("Face", cv_array)  # cv_array is a numpy array
            cv2.waitKey(1)  # clear the buffer
            detect_and_handle_faces(img)
def observe_faces(recognizer):
    cv2.namedWindow("Live View", cv2.CV_WINDOW_AUTOSIZE)
    cv2.namedWindow("Face", cv2.CV_WINDOW_AUTOSIZE)
    print "starting video capture..."
    while True:
        for cv_array in get_cv_img_from_canon_cam():
            try:
                cv2.imshow("Live View", cv_array)  # cv_array is a numpy array
                cv2.waitKey(1)
                img = cv.fromarray(cv_array)
            except (TypeError, cv2.error):
                print "Warning...got malformed JPEG data"
                continue  # cv_array was malformed, ignore and move to next frame
            detect_and_handle_faces(img, recognizer)
def observe_faces(recognizer):
    cv2.namedWindow("Live View", cv2.CV_WINDOW_AUTOSIZE)
    cv2.namedWindow("Face", cv2.CV_WINDOW_AUTOSIZE)
    sonos_device = find_sonos_device()
    print "starting video capture..."
    while True:
        for cv_array in get_cv_img_from_canon_cam():
            reset_has_played_today_if_necessary()
            try:
                cv2.imshow("Live View", cv_array)  # cv_array is a numpy array
                cv2.waitKey(1)
            except cv2.error:
                continue  # cv_array was malformed, ignore and move to next frame
            try:
                img = cv.fromarray(cv_array)
            except TypeError:
                print "Warning...got malformed JPEG data"
                continue
            if currently_playing_intro():
                continue  # dont do facial detection while music is playing
            detect_and_handle_faces(img, sonos_device, recognizer)
def canon_thread():
    for cv_array in get_cv_img_from_canon_cam():
        _handle_frame(cv_array, WINDOW2)
        gevent.sleep(0)  # yield to other thread