Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
millcake666 committed Nov 5, 2023
1 parent 0782688 commit fe29cef
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
5 changes: 3 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@
else:
text = "Looking center"


cv2.putText(frame, text, (90, 60), cv2.FONT_HERSHEY_DUPLEX, 1.6, (147, 58, 31), 2)

left_pupil = gaze.pupil_left_coords()
right_pupil = gaze.pupil_right_coords()
cv2.putText(frame, "Left pupil: " + str(left_pupil), (90, 130), cv2.FONT_HERSHEY_DUPLEX, 0.9, (147, 58, 31), 1)
cv2.putText(frame, "Right pupil: " + str(right_pupil), (90, 165), cv2.FONT_HERSHEY_DUPLEX, 0.9, (147, 58, 31), 1)

cv2.imshow("Demo", frame)
cv2.namedWindow("programs", cv2.WINDOW_NORMAL)
cv2.resizeWindow("programs", 1680, 1000)
cv2.imshow("programs", frame)

if cv2.waitKey(1) == 27:
break
Expand Down
65 changes: 65 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import cv2
from gaze_tracking import GazeTracking
from time import perf_counter
from os import walk
from random import randint

gaze = GazeTracking()
webcam = cv2.VideoCapture(0)

mypath = r'logo'
filenames = list(walk(mypath))[0][2]
logos_time = [0] * len(filenames)
time_old = perf_counter()
photos_shows = []

for i in range(5):
r1 = randint(0, len(filenames))
r2 = randint(0, len(filenames))
while True:
if r1 not in photos_shows:
photos_shows.append(r1)
break
r1 = randint(0, len(filenames))
while True:
if r2 not in photos_shows:
photos_shows.append(r2)
break
r2 = randint(0, len(filenames))

image1 = cv2.imread(filenames[r1])
image2 = cv2.imread(filenames[r2])
while True:
# We get a new frame from the webcam
_, frame = webcam.read()
# We send this frame to GazeTracking to analyze it
gaze.refresh(frame)
frame = gaze.annotated_frame()

pos = gaze.horizontal_ratio()
print(pos)

if pos is None:
# "Blinking"
pass
elif pos <= 0.6:
# "Looking right"
logos_time[r2] += perf_counter() - time_old
time_old = perf_counter()
elif pos > 0.6:
# "Looking left"
logos_time[r1] += perf_counter() - time_old
time_old = perf_counter()

left_pupil = gaze.pupil_left_coords()
right_pupil = gaze.pupil_right_coords()

cv2.namedWindow("programs", cv2.WINDOW_NORMAL)
cv2.resizeWindow("programs", 1680, 1000)
cv2.imshow("programs", frame)

if cv2.waitKey(1) == 27:
break

webcam.release()
cv2.destroyAllWindows()

0 comments on commit fe29cef

Please sign in to comment.