March 2020
Intermediate to advanced
366 pages
9h 8m
English
A cascade classifier can be loaded and applied to an image (grayscale) using the following code, where we first read the image, then convert it to grayscale, and finally detect all the faces using a cascade classifier:
import cv2
gray_img = cv2.cvtColor(cv2.imread('example.png'), cv2.COLOR_RGB2GRAY)cascade_clf = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')faces = cascade_clf.detectMultiScale(gray_img, scaleFactor=1.1, minNeighbors=3, flags=cv2.CASCADE_SCALE_IMAGE)
From the previous code, the detectMultiScale function comes with a number of options: