Book Image

Artificial Intelligence with Python

Book Image

Artificial Intelligence with Python

Overview of this book

Artificial Intelligence is becoming increasingly relevant in the modern world. By harnessing the power of algorithms, you can create apps which intelligently interact with the world around you, building intelligent recommender systems, automatic speech recognition systems and more. Starting with AI basics you'll move on to learn how to develop building blocks using data mining techniques. Discover how to make informed decisions about which algorithms to use, and how to apply them to real-world scenarios. This practical book covers a range of topics including predictive analytics and deep learning.
Table of Contents (23 chapters)
Artificial Intelligence with Python
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

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