def test_get_facial_landmarks_dlib(self):
     image_path = '../assets/examples/example_6.jpg'
     image = cv2.imread(image_path)
     rect = face_process.get_face_rect(image)
     landmarks = facial_landmarks_detection_dlib.get_facial_landmarks(
         image, rect)
     landmark_image = face_segmentation.draw_landmark(image, landmarks)
     cv2.imwrite('test_facial_landmarks.jpg', landmark_image)
     pass
 def test_landmarks_rectification(self):
     image_path = '../assets/targets/target_10.jpeg'
     image = cv2.imread(image_path)
     landmarks = facial_landmarks_detection_dlib.get_facial_landmarks(image)
     face_contour_landmarks = landmarks[0:17]
     image_size = tuple([image.shape[0], image.shape[1]])
     facial_region_index = face_segmentation.get_facial_indices(
         landmarks, image_size)
     gmm_color = face_segmentation.gmm_color_model(image,
                                                   facial_region_index)
     rectified_landmarks = landmarks_rectification.landmarks_rectify(
         image,
         face_contour_landmarks,
         gmm_color,
         resolution_list=tuple([512]))
     image = face_segmentation.draw_landmark(image, face_contour_landmarks)
     image = face_segmentation.draw_landmark(image, rectified_landmarks,
                                             (0, 0, 255))
     cv2.imwrite('test_rectify.jpg', image)
    def test__landmark_rectify(self):
        image_path = '../assets/examples/example_8.jpeg'
        image = cv2.imread(image_path)
        landmarks = facial_landmarks_detection_dlib.get_facial_landmarks(image)
        face_contour_landmarks = landmarks[0:17]
        image_size = tuple([image.shape[0], image.shape[1]])
        facial_region_index = face_segmentation.get_facial_indices(
            landmarks, image_size)
        gmm_color = face_segmentation.gmm_color_model(image,
                                                      facial_region_index)
        rectified_landmark = landmarks_rectification._landmark_rectify(
            image,
            face_contour_landmarks,
            gmm_color,
            search_dir='horizontal',
            window_size=25)

        image = face_segmentation.draw_landmark(image, landmarks)
        image = face_segmentation.draw_landmark(image,
                                                rectified_landmark,
                                                color=(0, 0, 255))
        cv2.imwrite('test_rectify.jpg', image)
    def test_facial_features(self):
        image_path = '../assets/targets/target_12.jpg'
        image = cv2.imread(image_path)
        landmarks = facial_landmarks_detection_dlib.get_facial_landmarks(image)
        _, triangle, triangle_mesh = face_segmentation.get_triangle_landmarks(
            landmarks)

        triangle, triangle_mesh = makeup_by_facial_features.get_triangle(
            landmarks)
        image = face_segmentation.draw_landmark(image, landmarks)

        for triangle in triangle_mesh:
            cv2.polylines(image, [np.asarray(triangle)], True, (0, 255, 255))
        cv2.imwrite('facial_features.jpg', image)
        pass
예제 #5
0
    def test_transfer_image(self):
        image_path = '../assets/examples/example_8.jpeg'
        image = cv2.imread(image_path)
        landmarks = facial_landmarks_detection_dlib.get_facial_landmarks(image)
        face_rect = face_process.select_face_rect(landmarks)
        face_image = image[face_rect['left_top'][1]:face_rect['bottom_right'][1],
                           face_rect['left_top'][0]:face_rect['bottom_right'][0]]
        cv2.imwrite('test.jpg', face_image)
        new_image, t = face_process.calc_image_transform(face_rect, image, resolution=512)
        cv2.imwrite('test1.jpg', new_image)
        new_landmarks = []
        for landmark in landmarks:
            new_landmarks.append(face_process.calc_transform_pts(landmark, t))

        new_image = face_segmentation.draw_landmark(new_image, new_landmarks)

        cv2.imwrite('test2.jpg', new_image)
        self.assertEquals(True,True)
예제 #6
0
    def test_calc_transform_mat(self):
        image_path = '../assets/examples/after-makeup1.jpeg'
        image = cv2.imread(image_path)
        landmarks = facial_landmarks_detection_dlib.get_facial_landmarks(image)
        height, width = image.shape[0], image.shape[1]
        origin_resolution = min(height, width)
        origin_center = tuple([origin_resolution /2, origin_resolution/2])
        image = image[0: origin_resolution, 0:origin_resolution]
        new_resolution = 256
        image = cv2.resize(image, dsize=(int(new_resolution),int(new_resolution)))
        new_center = tuple([new_resolution / 2, new_resolution/ 2])

        transform = face_process._calc_transfer_mat(origin_center, new_center, origin_resolution, new_resolution)

        new_landmarks = []
        for landmark in landmarks:
            new_landmarks.append(face_process.calc_transform_pts(landmark, transform))

        new_image = face_segmentation.draw_landmark(image, new_landmarks)
        cv2.imwrite('test1.jpg', new_image)