def test_move_sprite(self):
     landmark_overlay = LandmarkOverlayDecorator(self.base_component)
     self.hat.parent = landmark_overlay
     self.hat.sprite_anchors = ((25, 105), (60, 110))
     self.hat.anchored_landmark_indexes = (21, 22)
     result = self.hat.get_image()
     self.assertUnalteredImage(result)
 def test_parallel_offset(self):
     landmark_overlay = LandmarkOverlayDecorator(self.base_component)
     self.hat.parent = landmark_overlay
     self.hat.sprite_anchors = ((25, 105), (60, 110))
     self.hat.anchored_landmark_indexes = (21, 22)
     self.hat.parallel_offset = 30.5
     self.expected_landmark_distance = 300.0
     result = self.hat.get_image()
     self.assertUnalteredImage(result)
 def set_up_classification_decorator(self):
     self.classification_decorator = ClassificationDecorator(
         self.base_component)
     self.classifier = ConstantClassifier()
     first_class_decorator = self.hat
     second_class_decorator = LandmarkOverlayDecorator()
     self.classification_decorator.classifier = self.classifier
     self.classification_decorator.set_decorator_for_class(
         first_class_decorator, 0)
     self.classification_decorator.set_decorator_for_class(
         second_class_decorator, 1)
Exemple #4
0
def predicting_example():
    pygame.init()
    # Instanciate a new landmark detector
    detector_data_path = '../../data/shape_predictor_68_face_landmarks.dat'
    landmark_detector = LandmarkDetector(predictor_file=detector_data_path)

    # Create a frame component with landmarks
    base_component = LandmarkComponent(landmark_detector)

    # Instantiate and initialize the trained predictor
    predictor = PredictorInterface('../examples/mouth.pkl')
    predictor.initialize()

    landmarks = LandmarkOverlayDecorator(base_component)

    # Add decorator for the predictor
    predictor_decorator = ClassDecorator(parent_component=landmarks,
                                         classifier=predictor)
    sound = SoundDecorator(landmarks, "../sounds/boring.wav")
    predictor_decorator.set_decorator_for_class(sound, 0)
    multifaces = AllFaces.wrap(predictor_decorator)

    hat = AllFaces.wrap(SpriteDecorator(multifaces, '../sprites/Party_Hat'))

    use_webcam = True
    video_stream = cv2.VideoCapture("../../videos/trump.mp4")
    if use_webcam:
        video_stream = cv2.VideoCapture(0)
    while True:
        ret, frame = video_stream.read()
        frame = cv2.resize(frame, (0, 0), fx=1.0, fy=1.0)
        if use_webcam:
            frame = cv2.flip(frame, 1)
        base_component.set_image(frame)
        output = hat.get_image()
        output = cv2.resize(output, (0, 0), fx=1.0, fy=1.0)
        cv2.imshow("Frame", output)
        key = cv2.waitKey(1) & 0xFF
        if key == ord("q"):
            break
    cv2.destroyAllWindows()
    video_stream.release()
 def test_overlay_landmarks(self):
     landmark_overlay = LandmarkOverlayDecorator(self.base_component)
     result = landmark_overlay.get_image()
     self.assertUnalteredImage(result)
 def test_overlay_landmarks(self):
     landmark_overlay = LandmarkOverlayDecorator(self.base_component)
     result = landmark_overlay.get_image()
     self.assertUnalteredImage(result)