mtcnn webcam facial detection

Solutions on MaxInterview for mtcnn webcam facial detection by the best coders in the world

showing results for - "mtcnn webcam facial detection"
Johanna
02 May 2017
1import cv2
2from mtcnn.mtcnn import MTCNN
3
4detector = MTCNN()
5
6cap = cv2.VideoCapture(0) # if getting anonymous namespace error, use cv2.VideoCapture(0, cv2.CAP_DSHOW)
7while True: 
8    #Capture frame-by-frame
9    __, frame = cap.read()
10    
11    #Use MTCNN to detect faces
12    result = detector.detect_faces(frame)
13    if result != []:
14        for person in result:
15            bounding_box = person['box']
16            keypoints = person['keypoints']
17    
18            cv2.rectangle(frame,
19                          (bounding_box[0], bounding_box[1]),
20                          (bounding_box[0]+bounding_box[2], bounding_box[1] + bounding_box[3]),
21                          (0,155,255),
22                          2)
23    
24            cv2.circle(frame,(keypoints['left_eye']), 2, (0,155,255), 2)
25            cv2.circle(frame,(keypoints['right_eye']), 2, (0,155,255), 2)
26            cv2.circle(frame,(keypoints['nose']), 2, (0,155,255), 2)
27            cv2.circle(frame,(keypoints['mouth_left']), 2, (0,155,255), 2)
28            cv2.circle(frame,(keypoints['mouth_right']), 2, (0,155,255), 2)
29    #display resulting frame
30    cv2.imshow('frame',frame)
31    if cv2.waitKey(1) &0xFF == ord('q'):
32        break
33#When everything's done, release capture
34cap.release()
35cv2.destroyAllWindows()
similar questions
queries leading to this page
mtcnn webcam facial detection