Skip to content

Instantly share code, notes, and snippets.

@mortenboldt
Created December 19, 2018 16:53
Show Gist options
  • Save mortenboldt/b2e4775fb1bd8ff30f4b95d7c2924c01 to your computer and use it in GitHub Desktop.
Save mortenboldt/b2e4775fb1bd8ff30f4b95d7c2924c01 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import cv2
from mtcnn.mtcnn import MTCNN
detector = MTCNN()
for number in range(360):
if number % 10 != 0:
continue
image_name = "/tmp/frames/out-%04d.jpg" % (number + 1)
print(image_name)
image = cv2.imread(image_name)
result = detector.detect_faces(image)
if result:
bounding_box = result[0]['box']
keypoints = result[0]['keypoints']
cv2.rectangle(image,
(bounding_box[0], bounding_box[1]),
(bounding_box[0]+bounding_box[2], bounding_box[1] + bounding_box[3]),
(0,155,255),
2)
cv2.circle(image,(keypoints['left_eye']), 2, (0,155,255), 2)
cv2.circle(image,(keypoints['right_eye']), 2, (0,155,255), 2)
cv2.circle(image,(keypoints['nose']), 2, (0,155,255), 2)
cv2.circle(image,(keypoints['mouth_left']), 2, (0,155,255), 2)
cv2.circle(image,(keypoints['mouth_right']), 2, (0,155,255), 2)
cv2.imwrite("/tmp/frames/faces/out-%04d.jpg" % (number + 1), image)
#cv2.waitKey(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment