liveBook · Manning

Haar feature-based cascade classifier

As explained in Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi

A Haar feature-based cascade classifier is a cascade classifier that detects objects using Haar-like image features arranged in successive classification stages.

A Haar feature-based cascade classifier detects objects through successive classification stages built from Haar-like image features. For face detection, machine learning trains the cascade with positive images containing faces and negative images without them. section 9.3.1

A practical OpenCV detection workflow is:

  • Load a pretrained XML model shipped in OpenCV's data directory. section 9.3.1
  • Read a camera image, convert it to grayscale, and equalize its histogram to improve contrast. section 9.3.1
  • Call detectMultiScale to locate faces and return rectangles containing their coordinates and dimensions. section 9.3.1
  • Use smaller images when necessary to make detection faster for live video. section 9.6
>>> CLASSIFIER_PATH = f'{CV2_DIR}/data/haarcascade_frontalface_default.xml'

Locate the pretrained frontal-face XML file inside the installed OpenCV package before constructing the classifier. section 9.3.1

Detecting a face in a camera photo

Create a CascadeClassifier from the pretrained model, read photo.jpg, convert it to grayscale, equalize the histogram, and call detectMultiScale. A 640×480 image can produce one detected rectangle such as [215, 105, 268, 268]. section 9.3.1 section 9.6

How Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi covers it

How deep it goes
Explains positive and negative training images, pretrained models, preprocessing, detection calls, and speed tradeoffs without detailing cascade internals.
Examples
Uses a Raspberry Pi camera photo, a pretrained frontal-face XML file, grayscale conversion, histogram equalization, and detected-face rectangles.
What it assumes
Requires the cv2 package, a camera image, and an OpenCV XML model; teaches the detection workflow from model loading onward.
What you can do after
Apply it via OpenCV to detect faces in images and prepare detections for live camera control.
How it connects
Connects OpenCV, face detection, machine learning, histogram equalization, live video streams, and servo motors.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi. The section links point to the parts of the book it draws on.