Example #1
0
def main_loop(watchdog):
    face_identifier = FaceIdentifier()
    timed_frame_modify = graphics_utils.TimedFrameModify()

    # Frame workers are expected to define a process_frame function that takes a frame and returns a frame
    always_frame_workers = [
        DifferenceWakeup(),
    ]
    awake_frame_workers = [
        graphics_utils.FlipFrame(), # Flip the frame before we write text to it. "yaw taht retteb si"
        timed_frame_modify,
    ]

    frame_counter = 0
    while True:
        watchdog.stroke_watchdog()

        frame = capture_utils.load_frame_from_webcam()

        for frame_worker in always_frame_workers:
            frame = frame_worker.process_frame(frame)

        face = face_identifier.look_for_faces(frame)
        if face is not None:
            Wakeup.wakeup()
            face_identifier.track_face(frame, face, frame_counter)

            x, y, w, h = face
            cv2.rectangle(frame, (x, y), (x+w, y+h), DRAWING_COLOR, 15)

        have_match, prediction = face_identifier.check_stuff()
        if have_match:
            if prediction is None:
                action = functools.partial(graphics_utils.draw_xcentered_text, text='No match', height=100)

            else:
                action = functools.partial(graphics_utils.draw_xcentered_text, text=prediction, height=100)

                email = face_identifier.get_email_for_name(prediction)
                match_action(email, timed_frame_modify)

            timed_frame_modify.add_modification(action, 3, 'nametext', exclusive=True)

        frame_counter += 1

        if Wakeup.are_we_awake():
            for frame_worker in awake_frame_workers:
                frame = frame_worker.process_frame(frame)

            # display the frame, potentially break the loop
            cv2.imshow('Video', frame)
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
            cv2.imshow('Video', frame)
Example #2
0
 def process_frame(self, frame):
     if self.last_frame is not None:
         if DifferenceWakeup.do_frames_differ(frame, self.last_frame, 100):
             Wakeup.wakeup()
     self.last_frame = frame
     return frame