LIVE FACE DETECTION THROUGH WEBCAM USING PYTHON

# Face detection using webcam
import cv2

# trained dataset (from github)
trained_dataset = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

# capturing video via webcam
video = cv2.VideoCapture(0)

while True:
success, frame = video.read()

if success == True:
# converting color frame into gray 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), (255, 255, 255), 1)

# showing face dectected video
cv2.imshow('Live', frame)
key = cv2.waitKey(1)
if key == 13:
break
else:
break

Comments

Popular posts from this blog

MOTION DETECTION AND TRACKING USING OPENCV AND PYTHON

COLOR DETECTION USING OPENCV AND PYTHON

DETECTING ACCURACY LEVEL OF THE KNOWN AND TEST FACES USING PYTHON