-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrealtimeFT.py
More file actions
37 lines (26 loc) · 832 Bytes
/
realtimeFT.py
File metadata and controls
37 lines (26 loc) · 832 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
33
34
35
36
37
import cv2
face_classifier = cv2.CascadeClassifier(
cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'
)
'''
Access the device's camera
'''
video_capt = cv2.VideoCapture(0)
def detect_face(video):
gray_img = cv2.cvtColor(video, cv2.COLOR_BGR2GRAY)
faces = face_classifier.detectMultiScale(
gray_img, 1.1, 20, minSize=(40,40)
)
for (x, y, w, h) in faces:
cv2.rectangle(video,(x,y), (x + w, y + h), (0, 255, 0), 4)
return faces
while True:
result, video_frame = video_capt.read() # Read frames from video
if result is False:
break
faces = detect_face(video_frame)
cv2.imshow("Face Tracker", video_frame)
if cv2.waitKey(1) & 0x77 == ord('q'):
break
video_capt.release()
cv2.destroyAllWindows()