Building eye and nose detectors
The Haar cascades method can be extended to detect all types of objects. Let's see how to use it to detect the eyes and nose in the input video.
How to do it…
- Create a new Python file, and import the following packages:
import cv2 import numpy as np
- Load the face, eyes, and nose cascade files:
# Load face, eye, and nose cascade files face_cascade = cv2.CascadeClassifier('cascade_files/haarcascade_frontalface_alt.xml') eye_cascade = cv2.CascadeClassifier('cascade_files/haarcascade_eye.xml') nose_cascade = cv2.CascadeClassifier('cascade_files/haarcascade_mcs_nose.xml')
- Check whether the files loaded correctly:
# Check if face cascade file has been loaded if face_cascade.empty(): raise IOError('Unable to load the face cascade classifier xml file') # Check if eye cascade file has been loaded if eye_cascade.empty(): raise IOError('Unable to load the eye cascade classifier xml file') # Check if nose...