Skip to content

Commit 21b54cf

Browse files
authored
Added Eye Detection
1 parent 8f56f4a commit 21b54cf

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

eye_detection/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
USER GUIDE
2+
Setup and activate virtual environment :
3+
4+
For Unix based systems please execute the following command to create venv and install requirements.
5+
6+
make init
7+
source .venv/bin/activate
8+
9+
Pre-requisites
10+
11+
1) Python Open-cv
12+
$ pip install opencv-python
13+
14+
2) Python Numpy
15+
$ pip install numpy
16+
17+
How to run the script?
18+
19+
$ python eye_detector.py
20+
21+
Once done, Web Camera will start with the detecting Eyes

eye_detection/eye_detector.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import numpy as np
2+
import cv2
3+
face_cascade = cv2.CascadeClassifier(
4+
cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
5+
eye_cascade = cv2.CascadeClassifier(
6+
cv2.data.haarcascades + 'haarcascade_eye.xml')
7+
cap = cv2.VideoCapture(0)
8+
while 1:
9+
ret, img = cap.read()
10+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
11+
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
12+
for (x, y, w, h) in faces:
13+
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
14+
roi_gray = gray[y:y+h, x:x+w]
15+
roi_color = img[y:y+h, x:x+w]
16+
eyes = eye_cascade.detectMultiScale(roi_gray)
17+
for (ex, ey, ew, eh) in eyes:
18+
cv2.rectangle(roi_color, (ex, ey), (ex+ew, ey+eh), (0, 255, 0), 2)
19+
cv2.imshow('Web Cam Input', img)
20+
k = cv2.waitKey(30) & 0xff
21+
if k == 27:
22+
break
23+
cap.release()
24+
cv2.destroyAllWindows()

eye_detection/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
opencv-python
2+
numpy

0 commit comments

Comments
 (0)