Last active
December 19, 2018 08:33
-
-
Save mortenboldt/3910081e9d4d7c6634ac8430b09486e5 to your computer and use it in GitHub Desktop.
mtcnn face detect
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
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| import cv2 | |
| from mtcnn.mtcnn import MTCNN | |
| detector = MTCNN() | |
| image = cv2.imread("lone.jpg") | |
| result = detector.detect_faces(image) | |
| # Result is an array with all the bounding boxes detected. We know that forthis particular image there is only one. | |
| 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.imshow("face", image) | |
| cv2.waitKey(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment