September 2019
Intermediate to advanced
420 pages
10h 29m
English
Although OpenCV provides a very efficient implementation of AdaBoost, it is hidden under the Haar cascade classifier. Haar cascade classifiers are a very popular tool for face detection, which we can illustrate through the example of the Lena image:
In [1]: img_bgr = cv2.imread('data/lena.jpg', cv2.IMREAD_COLOR)... img_gray = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2GRAY)
After loading the image in both color and grayscale, we load a pretrained Haar cascade:
In [2]: import cv2... filename = 'data/haarcascade_frontalface_default.xml'... face_cascade = cv2.CascadeClassifier(filename)
The classifier will then detect faces present in the image using the following function call:
In [3]: faces = face_cascade.detectMultiScale(img_gray, ...
Read now
Unlock full access