Created
September 8, 2020 23:45
-
-
Save igorrendulic/9de0a06c22ca637a493fa8f3aedca31d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def add_face_markers(frame): | |
""" | |
Adding face markers onto a single frame | |
""" | |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
rects = detector(gray, 0) | |
for (i, rect) in enumerate(rects): | |
shape = predictor(gray, rect) | |
shape = face_utils.shape_to_np(shape) | |
# convert dlib's rectangle to a OpenCV-style bounding box | |
# [i.e., (x, y, w, h)], then draw the face bounding box | |
(x, y, w, h) = face_utils.rect_to_bb(rect) | |
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) | |
# show the face number | |
cv2.putText(frame, "Face #{}".format(i + 1), (x - 10, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) | |
for (x,y) in shape: | |
cv2.circle(frame, (x,y), 1, (0,255,0), -1) | |
return frame |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment