mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-11-04 14:39:42 +08:00
stability update
This commit is contained in:
parent
8710f14c4a
commit
4f41bd9514
132
EyeTrackVR.py
132
EyeTrackVR.py
@ -4,10 +4,13 @@ import threading
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
try:
|
||||||
fy= open("camport.txt","r+")
|
fy= open("camport.txt","r+")
|
||||||
camport = fy.read().strip()
|
camport = fy.read().strip()
|
||||||
fy.close
|
fy.close
|
||||||
|
except:
|
||||||
|
print('Error: Run Gui first and adjust camera port')
|
||||||
|
time.sleep(5)
|
||||||
bl = False
|
bl = False
|
||||||
cap = cv2.VideoCapture(int(camport))
|
cap = cv2.VideoCapture(int(camport))
|
||||||
|
|
||||||
@ -21,25 +24,45 @@ def lefteye():
|
|||||||
break
|
break
|
||||||
|
|
||||||
################################################ Reads values set in gui, needs rework to single config file
|
################################################ Reads values set in gui, needs rework to single config file
|
||||||
fy= open("valueY.txt","r+")
|
try:
|
||||||
vy = fy.read().strip()
|
fy= open("valueY.txt","r+")
|
||||||
fy.close
|
vy = fy.read().strip()
|
||||||
|
fy.close
|
||||||
|
except:
|
||||||
|
print('Error: Run Gui first and adjust Value Y')
|
||||||
|
time.sleep(5)
|
||||||
################################################
|
################################################
|
||||||
fx= open("valueX.txt","r+")
|
try:
|
||||||
vx = fx.read().strip()
|
fx= open("valueX.txt","r+")
|
||||||
fx.close
|
vx = fx.read().strip()
|
||||||
|
fx.close
|
||||||
|
except:
|
||||||
|
print('Error: Run Gui first and adjust Value X')
|
||||||
|
time.sleep(5)
|
||||||
################################################
|
################################################
|
||||||
vyll= open("valueYl.txt","r+")
|
try:
|
||||||
vyl = vyll.read().strip()
|
vyll= open("valueYl.txt","r+")
|
||||||
vyll.close
|
vyl = vyll.read().strip()
|
||||||
|
vyll.close
|
||||||
|
except:
|
||||||
|
print('Error: Run Gui first and adjust Value Y L')
|
||||||
|
time.sleep(5)
|
||||||
################################################
|
################################################
|
||||||
vxll= open("valueXl.txt","r+")
|
try:
|
||||||
vxl = vxll.read().strip()
|
vxll= open("valueXl.txt","r+")
|
||||||
vxll.close
|
vxl = vxll.read().strip()
|
||||||
|
vxll.close
|
||||||
|
except:
|
||||||
|
print('Error: Run Gui first and adjust Value X L')
|
||||||
|
time.sleep(5)
|
||||||
################################################
|
################################################
|
||||||
thresh= open("thresh.txt","r+")
|
try:
|
||||||
threshr = thresh.read().strip()
|
thresh= open("thresh.txt","r+")
|
||||||
thresh.close
|
threshr = thresh.read().strip()
|
||||||
|
thresh.close
|
||||||
|
except:
|
||||||
|
print('Error: Run Gui first and adjust threshold value')
|
||||||
|
time.sleep(5)
|
||||||
################################################
|
################################################
|
||||||
|
|
||||||
try: # trys at set size if it errors it will revert to working size/ doesnt do what was orrigionally planed, it kinda helps, entire thing will eventually go into try and except later
|
try: # trys at set size if it errors it will revert to working size/ doesnt do what was orrigionally planed, it kinda helps, entire thing will eventually go into try and except later
|
||||||
@ -47,52 +70,53 @@ def lefteye():
|
|||||||
except:
|
except:
|
||||||
roi = frame[100: 300, 200: 316]
|
roi = frame[100: 300, 200: 316]
|
||||||
|
|
||||||
|
try:
|
||||||
|
rows, cols, _ = roi.shape
|
||||||
|
gray_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
|
||||||
|
gray_roi = cv2.GaussianBlur(gray_roi, (7, 7), 0)
|
||||||
|
|
||||||
rows, cols, _ = roi.shape
|
_, threshold = cv2.threshold(gray_roi, int(threshr), 255, cv2.THRESH_BINARY_INV)
|
||||||
gray_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
|
contours, _ = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
||||||
gray_roi = cv2.GaussianBlur(gray_roi, (7, 7), 0)
|
contours = sorted(contours, key=lambda x: cv2.contourArea(x), reverse=True)
|
||||||
|
|
||||||
_, threshold = cv2.threshold(gray_roi, int(threshr), 255, cv2.THRESH_BINARY_INV)
|
for cnt in contours:
|
||||||
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)
|
|
||||||
|
|
||||||
|
(x, y, w, h) = cv2.boundingRect(cnt)
|
||||||
|
|
||||||
|
|
||||||
openes = 95
|
openes = 95
|
||||||
if h <= 25: #way to find if eye is closed and sets value (hopefully will train tensorflow model for correct openess detection)
|
if h <= 25: #way to find if eye is closed and sets value (hopefully will train tensorflow model for correct openess detection)
|
||||||
openes = 0
|
openes = 0
|
||||||
|
|
||||||
print('Left: x:', x, 'y:', y, 'openess:', openes)
|
print('Left: x:', x, 'y:', y, 'openess:', openes)
|
||||||
print('Right: x:', x, 'y:', y, 'openess:', openes)
|
print('Right: x:', x, 'y:', y, 'openess:', openes)
|
||||||
|
|
||||||
cv2.line(threshold, (x + int(w/2), 0), (x + int(w/2), rows), (255, 0, 0), 1) #visualizes eyetracking on threshold
|
cv2.line(threshold, (x + int(w/2), 0), (x + int(w/2), rows), (255, 0, 0), 1) #visualizes eyetracking on threshold
|
||||||
cv2.line(threshold, (0, y + int(h/2)), (cols, y + int(h/2)), (255, 0, 0), 1)
|
cv2.line(threshold, (0, y + int(h/2)), (cols, y + int(h/2)), (255, 0, 0), 1)
|
||||||
cv2.drawContours(threshold, [cnt], -1, (255, 0, 0), 3)
|
cv2.drawContours(threshold, [cnt], -1, (255, 0, 0), 3)
|
||||||
cv2.rectangle(threshold, (x, y), (x + w, y + h), (255, 0, 0), 2)
|
cv2.rectangle(threshold, (x, y), (x + w, y + h), (255, 0, 0), 2)
|
||||||
|
|
||||||
cv2.line(gray_roi, (x + int(w/2), 0), (x + int(w/2), rows), (255, 0, 0), 1) #visualizes eyetracking on greyscale
|
cv2.line(gray_roi, (x + int(w/2), 0), (x + int(w/2), rows), (255, 0, 0), 1) #visualizes eyetracking on greyscale
|
||||||
cv2.line(gray_roi, (0, y + int(h/2)), (cols, y + int(h/2)), (255, 0, 0), 1)
|
cv2.line(gray_roi, (0, y + int(h/2)), (cols, y + int(h/2)), (255, 0, 0), 1)
|
||||||
cv2.drawContours(gray_roi, [cnt], -1, (255, 0, 0), 3)
|
cv2.drawContours(gray_roi, [cnt], -1, (255, 0, 0), 3)
|
||||||
cv2.rectangle(gray_roi, (x, y), (x + w, y + h), (255, 0, 0), 2)
|
cv2.rectangle(gray_roi, (x, y), (x + w, y + h), (255, 0, 0), 2)
|
||||||
break
|
break
|
||||||
|
|
||||||
if h == 0: #basically useless lol
|
|
||||||
print('no eye detected"')
|
|
||||||
|
|
||||||
|
|
||||||
|
if h == 0: #basically useless lol
|
||||||
|
print('no eye detected"')
|
||||||
|
|
||||||
|
|
||||||
cv2.imshow("Threshold", threshold)
|
|
||||||
cv2.imshow("GreyScale", gray_roi)
|
cv2.imshow("Threshold", threshold)
|
||||||
#cv2.imshow("Roi", roi)
|
cv2.imshow("GreyScale", gray_roi)
|
||||||
key = cv2.waitKey(30)
|
#cv2.imshow("Roi", roi)
|
||||||
|
key = cv2.waitKey(30)
|
||||||
|
except:
|
||||||
|
print('ERROR 1: Something went wrong trying to track your eye. Contact the ')
|
||||||
|
|
||||||
print('###############> initailizing <###############')
|
print('###############> initailizing <###############')
|
||||||
|
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
lefteye()
|
lefteye()
|
||||||
|
print('Running:')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user