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:

Fun with eyes

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') img = cv2.imread('input.jpg') sunglasses_img ...

Get OpenCV: Computer Vision Projects with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.