Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Eye Tracking Python Script #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ Description
- tictactoe <br />
A cli-based tictactoe game to play with the computer. <br/>
[Rounak Vyas](http://www.github.com/itsron717)

- eyetracking <br />
An advanced eye-tracking system with OpenCV and data extracted from a recorded .flv file. The program bounds the box of the iris and scales on the axis. <br/>
[Akash Ramjyothi](https://github.com/Akash-Ramjyothi)
10 changes: 10 additions & 0 deletions scripts/eyetracking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Advanced-Eye-Tracking

Developed an advanced eye-tracking system with OpenCV and data extracted from a recorded .flv file. The program bounds the box of the iris and scales on the axis.

## Sample Demo:
![ezgif com-gif-maker (3)](https://user-images.githubusercontent.com/54114888/94371563-20226c80-0115-11eb-98ed-23562a0db853.gif)

## Usage
`python main.py`

Binary file added scripts/eyetracking/eye_recording.flv
Binary file not shown.
36 changes: 36 additions & 0 deletions scripts/eyetracking/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import cv2
import numpy as np

cap = cv2.VideoCapture("scripts/eyetracking/eye_recording.flv")

while True:
ret, frame = cap.read()
if ret is False:
break

roi = frame[269: 795, 537: 1416]
rows, cols, _ = roi.shape
gray_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
gray_roi = cv2.GaussianBlur(gray_roi, (7, 7), 0)

_, threshold = cv2.threshold(gray_roi, 3, 255, cv2.THRESH_BINARY_INV)
_, contours, _ = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key=lambda x: cv2.contourArea(x), reverse=True)

for cnt in contours:
(x, y, w, h) = cv2.boundingRect(cnt)

#cv2.drawContours(roi, [cnt], -1, (0, 0, 255), 3)
cv2.rectangle(roi, (x, y), (x + w, y + h), (255, 0, 0), 2)
cv2.line(roi, (x + int(w/2), 0), (x + int(w/2), rows), (0, 255, 0), 2)
cv2.line(roi, (0, y + int(h/2)), (cols, y + int(h/2)), (0, 255, 0), 2)
break

cv2.imshow("Threshold", threshold)
cv2.imshow("gray roi", gray_roi)
cv2.imshow("Roi", roi)
key = cv2.waitKey(30)
if key == 27:
break

cv2.destroyAllWindows()