Real-Time Eye Detection OpenCV Python With Source Code
The Real-Time Eye Detection OpenCV Python was developed using Python Detection OpenCV, this Eye Tracking OpenCV Python, we’re going to discuss object detection with Haar Cascades. We’ll do eye detection to start. In order to do object recognition/detection with cascade files, you first need cascade files. For the extremely popular tasks, these already exist. Detecting things like faces, cars, smiles, eyes, and license plates for example are all pretty prevalent.
A Eye Detection Using OpenCV Python you will learn about detecting a human eye with the feature mappers knows as haar cascades. Here in the project, we will use the python language along with the OpenCV library for the algorithm execution and image processing respectively. The haar cascades we are going to use in the project are pretrained and stored along with the OpenCV library as haarcascade_eye_default.xml
The project develops a basic understanding of the systems such as driver drowsiness detection, eye detection, face detection and also the haar cascades usage with the OpenCV library.
In this Project also includes a downloadable Detection OpenCV Python Code for free, just find the downloadable source code below and click to start downloading.
By the way if you are new to python programming and you don’t know what would be the the Python IDE to use, I have here a list of Best Python IDE for Windows, Linux, Mac OS that will suit for you. I also have here How to Download and Install Latest Version of Python on Windows.
To start creating a Real-Time Eye Detection OpenCV Python, make sure that you have installed Python in your computer.
Real-Time Eye Detection OpenCV Python : Prerequisites
Before starting with this Python project with source code, you should be familiar with the computer vision library of Python that is OpenCV.
OpenCV are the Python package that are necessary for this project in Python. To install this, simply run this pip command in your terminal:
- pip install opencv-python
Real-Time Eye Detection OpenCV Python With Source Code: Steps on how to build the project
Time needed: 5 minutes.
These are the steps on how to build Real-Time Eye Detection OpenCV Python With Source Code
- Step 1: Download and unzip the zip file.
The project folder contains 2 files:
1.) eye_detection.py – a main python file to detect the eye.
2.) haarcascade_eye.xml – a file that load cascade from the camera. - Step 2: Creating a code for eye detection.
Next, create a code that can detect human eye and name it as “eye_detection.py“.
- Step 3: Run eye_detection.py.
The beginner Python project is now complete, you can run the Python file from the command prompt. Make sure to give an camera path using ‘-c’ argument.
Real-Time Eye Detection OpenCV Python : Complete Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import cv2 # Load the cascade face_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') # To capture video from webcam. cap = cv2.VideoCapture(0) # To use a video file as input # cap = cv2.VideoCapture('filename.mp4') while True: # Read the frame _, img = cap.read() # Convert to grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Detect the faces faces = face_cascade.detectMultiScale(gray, 1.1, 4) # Draw the rectangle around each face for (x, y, w, h) in faces: cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2) # Display cv2.imshow('img', img) # Stop if escape key is pressed k = cv2.waitKey(30) & 0xff if k==27: break # Release the VideoCapture object cap.release() |
Real-Time Eye Detection OpenCV Python : Output

Run Quick Virus Scan for secure Download
Run Quick Scan for secure DownloadDownload Source Code below
Summary
In this tutorial you will learn about detecting a blink of human eye with the feature mappers knows as haar cascades. Here in the project, we will use the python language along with the OpenCV library for the algorithm execution and image processing respectively. The haar cascades we are going to use in the project are pretrained and stored along with the OpenCV library as haarcascade_eye.xml files. The project develops a basic understanding of the systems such as driver eye detection, face detection and also the haar cascades usage with the OpenCV library.
Other Related Articles
Related Articles
- Code For Game in Python: Python Game Projects With Source Code
- Best Python Projects With Source Code 2020 FREE DOWNLOAD
- How to Make a Point of Sale In Python With Source Code 2021
- Python Code For Food Ordering System | FREE DOWNLOAD | 2020
- Inventory Management System Project in Python With Source Code
Inquiries
If you have any questions or suggestions about Real-Time Eye Detection OpenCV Python With Source Code, please feel free to leave a comment below.