O'Reilly logo

OpenCV with Python By Example by Prateek Joshi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required