-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (24 loc) · 914 Bytes
/
main.py
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
33
34
35
36
37
38
import cv2
import dlib
def detect_faces():
cap = cv2.VideoCapture(0)
detector = dlib.get_frontal_face_detector()
while True:
ret, frame = cap.read()
if not ret:
break
frame = cv2.flip(frame, 1)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = detector(gray)
i = 0
for face in faces:
x, y = face.left(), face.top()
x1, y1 = face.right(), face.bottom()
cv2.rectangle(frame, (x, y), (x1, y1), (0, 255, 0), 2)
i += 1
cv2.putText(frame, 'face num ' + str(i), (x-10, y-10),
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)
print(face, i)
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
yield frame_rgb
cap.release()