Fun with eyes
Now that we know how to detect eyes in an image, let's see if we can do something fun with it. We can do something like what is shown in the following screenshot:
Let's look at the code to see how to do something like this:
import cv2 import numpy as np face_cascade = cv2.CascadeClassifier('./cascade_files/haarcascade_frontalface_alt.xml') eye_cascade = cv2.CascadeClassifier('./cascade_files/haarcascade_eye.xml') if face_cascade.empty(): raise IOError('Unable to load the face cascade classifier xml file') if eye_cascade.empty(): raise IOError('Unable to load the eye cascade classifier xml file') cap = cv2.VideoCapture(0) sunglasses_img = cv2.imread('images/sunglasses.png') while True: ret, frame = cap.read() frame = cv2.resize(frame, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA) vh, vw = frame.shape[:2] vh, vw = int(vh), int(vw) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, scaleFactor...