February 2019
Beginner to intermediate
308 pages
7h 42m
English
Face detection can be implemented by the OpenCV library in Python. OpenCV is an open source computer vision library for computer vision tasks. Let's see how we can use OpenCV for face detection.
First, we import OpenCV:
import cv2
Next, let's load a pre-trained cascade classifier for face detection. This cascade classifier can be found in the accompanying GitHub repository and should have been downloaded to your computer (refer to the Technical requirements section):
face_cascades = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
Next, we define a function that takes in an image, performs face detection on the image, and draws a bounding box around the image:
def detect_faces(img, draw_box=True): # convert ...