In this section, we discuss how human faces can be detected from webcam images. A USB webcam needs to be connected to Raspberry Pi 3 to implement real-time human face detection.
Building a face detector application
How to do it...
- Import the necessary packages:
import cv2 import numpy as np
- Load the face cascade file:
frontalface_cascade= cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
- Check whether the face cascade file has been loaded:
if frontalface_cascade.empty(): raiseIOError('Unable to load the face cascade classifier xml file')
- Initialize the video capture object:
capture = cv2.VideoCapture(0)
- Define the scaling factor:
scale_factor = 0.5
- Perform the operation until...