FACE DETECTION IN VIDEO USING PYTHON
# Face detection in video
import cv2
# trained dataset (from github)
trained_dataset = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# getting video
video = cv2.VideoCapture(r'video\face-demographics-walking-and-pause.mp4')
while True:
success, frame = video.read()
if success == True:
# converting color frame to grayscale frame
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# getting values of x-axis, y-axis, width, height
faces = trained_dataset.detectMultiScale(gray_frame)
""" print(faces) -> return values of x-axis, y-axis, width, height """
# creating rectangle around the face
for x, y, w, h in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
# showing face dectected video
cv2.imshow('Video', frame)
cv2.waitKey(1)
else:
break
Also Refer: Face detection in image using python
Comments