-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmtcnn_test.py
More file actions
32 lines (23 loc) · 1012 Bytes
/
Copy pathmtcnn_test.py
File metadata and controls
32 lines (23 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
# example of detecting and alignment with MTCNN
import cv2
import sys
from mtcnn.mtcnn import MTCNN
detector = MTCNN()
image = cv2.cvtColor(cv2.imread("test_images/1.jpg"), cv2.COLOR_BGR2RGB)
result = detector.detect_faces(image)
# Result is an array with all the bounding boxes detected. We know that for 'ivan.jpg' 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,0),
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("test", cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
cv2.waitKey()