-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathFace detection on recorded videos
44 lines (32 loc) · 1.11 KB
/
Face detection on recorded videos
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
39
40
41
42
43
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 28 11:37:27 2019
@author: vchan
"""
# OpenCV Python program to detect cars in video frame
# import libraries of python OpenCV
import cv2
import face_recognition
# capture frames from a video
cap = cv2.VideoCapture( r'C:\Users\vchan\OneDrive\Desktop\Untitled Folder\people_presenting.mp4',0)
# Initialize variables
face_locations = []
while True:
# Grab a single frame of video
ret, frame = cap.read()
# Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
rgb_frame = frame[:, :, ::-1]
# Find all the faces in the current frame of video
face_locations = face_recognition.face_locations(rgb_frame)
# Display the results
for top, right, bottom, left in face_locations:
# Draw a box around the face
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
# Display the resulting image
cv2.imshow('Video', frame)
# Wait for Enter key to stop
if cv2.waitKey(25) == 13:
break
# Release everything if job is finished
cap.release()
cv2.destroyAllWindows()