Last active
July 3, 2020 15:04
-
-
Save LimaGuilherme/995719577da0724dabba6d11e3f648b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import dlib | |
import numpy as np | |
initial_image = cv2.imread('images/image9.jpg') | |
initial_image_in_rgb = cv2.cvtColor(initial_image, cv2.COLOR_BGR2RGB) | |
reference_image = initial_image_in_rgb.copy() | |
classifier_path = dlib.shape_predictor('classifier/shape_predictor_68_face_landmarks.dat') | |
frontal_face_detector = dlib.get_frontal_face_detector() | |
rectangles = frontal_face_detector(initial_image, 1) | |
for k, d in enumerate(rectangles): | |
cv2.rectangle(reference_image, (d.left(), d.top()), (d.right(), d.bottom()), (255, 255, 0), 2) | |
landmarks = [] | |
for rectangle in rectangles: | |
landmarks.append(np.matrix([[p.x, p.y] for p in classifier_path(reference_image, rectangle).parts()])) | |
for landmark in landmarks: | |
for index, point in enumerate(landmark): | |
point_center = (point[0, 0], point[0, 1]) | |
cv2.circle(reference_image, point_center, 3, (255, 255, 0), -1) | |
cv2.putText(reference_image, str(index), point_center, cv2.FONT_HERSHEY_COMPLEX, 3, (255, 255, 255), 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment