Eye detection and tracking
Eye detection works very similarly to face detection. Instead of using a face cascade file, we will use an eye cascade file. Create a new python file and import the following packages:
import cv2 import numpy as np
Load the Haar cascade files corresponding to face and eye detection:
# Load the Haar cascade files for face and eye face_cascade = cv2.CascadeClassifier('haar_cascade_files/haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier('haar_cascade_files/haarcascade_eye.xml') # Check if the face cascade file has been loaded correctly if face_cascade.empty(): raise IOError('Unable to load the face cascade classifier xml file') # Check if the eye cascade file has been loaded correctly if eye_cascade.empty(): raise IOError('Unable to load the eye cascade classifier xml file')
Initialize the video capture object and define the scaling factor:
# Initialize the video capture object cap...