-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfaceRecognition.py
More file actions
30 lines (19 loc) · 965 Bytes
/
faceRecognition.py
File metadata and controls
30 lines (19 loc) · 965 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
import cv2
face_classifier = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
video_capture = cv2.VideoCapture(0)
def detect_bounding_box(vid):
gray_image = cv2.cvtColor(vid, cv2.COLOR_BGR2GRAY)
faces = face_classifier.detectMultiScale(gray_image, 1.1, 5, minSize=(40, 40))
for (x, y, w, h) in faces:
cv2.rectangle(vid, (x, y), (x + w, y + h), (0, 255, 0), 4)
return faces
while True:
result, video_frame = video_capture.read() # read frames from the video
if result is False:
break # terminate the loop if the frame is not read successfully
faces = detect_bounding_box(video_frame) # apply the function we created to the video frame
cv2.imshow("My Face Detection Project", video_frame) # display the processed frame in a window named "My Face Detection Project"
if cv2.waitKey(1) & 0xFF == ord("q"):
break
video_capture.release()
cv2.destroyAllWindows()