Skip to content

Commit 9bcf8c7

Browse files
authored
Merge pull request #651 from avats101/main
Added Eye Detection
2 parents 8f56f4a + 885be40 commit 9bcf8c7

File tree

3 files changed

+46
-0
lines changed

3 files changed

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