mirror of
https://github.com/EyeTrackVR/EyeTrackVR-Docs.git
synced 2025-11-04 14:49:44 +08:00
Initial file upload
This commit is contained in:
parent
2a503e5906
commit
bc338d2326
96
eye_tracking_vr.py
Normal file
96
eye_tracking_vr.py
Normal file
@ -0,0 +1,96 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
import threading
|
||||
from multiprocessing import Process,Queue,Pipe
|
||||
cap = cv2.VideoCapture(3)
|
||||
bl = False
|
||||
|
||||
import time
|
||||
|
||||
def lefteye():
|
||||
|
||||
|
||||
h = 1
|
||||
textl = 1
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
if ret is False:
|
||||
break
|
||||
|
||||
|
||||
fy= open("valueY.txt","r+")
|
||||
vy = fy.read().strip()
|
||||
fy.close
|
||||
|
||||
###########
|
||||
|
||||
fx= open("valueX.txt","r+")
|
||||
vx = fx.read().strip()
|
||||
fx.close
|
||||
|
||||
################
|
||||
|
||||
vyll= open("valueYl.txt","r+")
|
||||
vyl = vyll.read().strip()
|
||||
vyll.close
|
||||
|
||||
#############
|
||||
vxll= open("valueXl.txt","r+")
|
||||
vxl = vxll.read().strip()
|
||||
vxll.close
|
||||
|
||||
|
||||
try:
|
||||
roi = frame[int(vxl): int(float(vy)), int(vyl): int(float(vx))]
|
||||
except:
|
||||
roi = frame[100: 300, 200: 316]
|
||||
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, 18, 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)
|
||||
#print(x, y,)
|
||||
textl = str(x) + ' ' + str(y)
|
||||
|
||||
cv2.drawContours(roi, [cnt], -1, (0, 0, 255), 3)
|
||||
cv2.rectangle(roi, (x, y), (x + w, y + h), (255, 0, 0), 2)
|
||||
if h <= 10:
|
||||
print('blink')
|
||||
textl = 'blink'
|
||||
if w >= 50:
|
||||
print('eyeclosed')
|
||||
textl = 'eyeclosed'
|
||||
eyeopeness1 = h * 2 * w
|
||||
print(eyeopeness1)
|
||||
cv2.putText(frame, textl, (200, 300), cv2.FONT_HERSHEY_DUPLEX, 0.9, (100, 58, 31), 1)
|
||||
cv2.line(roi, (x + int(w/2), 0), (x + int(w/2), rows), (100, 0, 255), 1)
|
||||
cv2.line(roi, (0, y + int(h/2)), (cols, y + int(h/2)), (0, 255, 0), 1)
|
||||
break
|
||||
if textl == 'blink':
|
||||
cv2.putText(frame, textl, (200, 300), cv2.FONT_HERSHEY_DUPLEX, 0.9, (100, 58, 31), 1)
|
||||
if textl == 'eyeclosed':
|
||||
cv2.putText(frame, textl, (200, 300), cv2.FONT_HERSHEY_DUPLEX, 0.9, (100, 58, 31), 1)
|
||||
if h == 0:
|
||||
print('no eye detected"')
|
||||
iii = 0
|
||||
|
||||
|
||||
cv2.imshow("Threshold", threshold)
|
||||
cv2.imshow("gray roi", gray_roi)
|
||||
cv2.imshow("Roi", roi)
|
||||
key = cv2.waitKey(30)
|
||||
|
||||
print('###############> initailizing threads <###############')
|
||||
t1 = threading.Thread(target=lefteye)
|
||||
#t2 = threading.Thread(target=valuy)
|
||||
t1.start()
|
||||
#t2.start()
|
||||
t1.join()
|
||||
#t2.join()
|
||||
cv2.destroyAllWindows()
|
||||
132
guikiv.py
Normal file
132
guikiv.py
Normal file
@ -0,0 +1,132 @@
|
||||
import kivy
|
||||
from multiprocessing import Process,Queue,Pipe
|
||||
kivy.require("1.9.1")
|
||||
|
||||
from kivy.app import App
|
||||
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
|
||||
from kivy.uix.slider import Slider
|
||||
|
||||
from kivy.uix.label import Label
|
||||
|
||||
from kivy.uix.floatlayout import FloatLayout
|
||||
|
||||
from kivy.properties import NumericProperty
|
||||
|
||||
from kivy.uix.scatter import Scatter
|
||||
|
||||
from kivy.uix.textinput import TextInput
|
||||
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
|
||||
from kivy.core.window import Window
|
||||
Window.size = (500, 200)
|
||||
|
||||
class WidgetContainer(GridLayout):
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
|
||||
super(WidgetContainer, self).__init__(**kwargs)
|
||||
|
||||
|
||||
self.cols = 3
|
||||
|
||||
|
||||
self.xcc = Slider(min = 1, max = 800,
|
||||
value_track = True,
|
||||
value_track_color =[1, 1, 1, 1])
|
||||
|
||||
|
||||
self.add_widget(Label(text ='Search Size X R'))
|
||||
self.add_widget(self.xcc)
|
||||
|
||||
|
||||
|
||||
self.xValue = Label(text ='1')
|
||||
|
||||
self.add_widget(self.xValue)
|
||||
|
||||
|
||||
self.xcc.bind(value = self.on_value)
|
||||
|
||||
###################################
|
||||
|
||||
|
||||
self.Y = Slider(min = 1, max = 2000,
|
||||
value_track = True,
|
||||
value_track_color =[1, 1, 1, 1])
|
||||
|
||||
|
||||
self.add_widget(Label(text ='Search Size Y R'))
|
||||
self.add_widget(self.Y)
|
||||
|
||||
|
||||
|
||||
self.YV = Label(text ='1')
|
||||
self.add_widget(self.YV)
|
||||
|
||||
|
||||
|
||||
self.Y.bind(value = self.on_value1)
|
||||
###############################################
|
||||
|
||||
self.xlc = Slider(min = 1, max = 800,
|
||||
value_track = True,
|
||||
value_track_color =[1, 1, 1, 1])
|
||||
self.add_widget(Label(text ='Search Size X L'))
|
||||
self.add_widget(self.xlc)
|
||||
self.xlValue = Label(text ='1')
|
||||
self.add_widget(self.xlValue)
|
||||
self.xlc.bind(value = self.on_value2)
|
||||
####################################################
|
||||
|
||||
self.ylc = Slider(min = 1, max = 800,
|
||||
value_track = True,
|
||||
value_track_color =[1, 1, 1, 1])
|
||||
self.add_widget(Label(text ='Search Size Y L'))
|
||||
self.add_widget(self.ylc)
|
||||
self.ylValue = Label(text ='1')
|
||||
self.add_widget(self.ylValue)
|
||||
self.ylc.bind(value = self.on_value3)
|
||||
|
||||
#####################################################
|
||||
|
||||
def on_value(self, instance, brightness):
|
||||
self.xValue.text = "% d"% brightness
|
||||
fx= open("valueX.txt","w+")
|
||||
fx.write(self.xValue.text)
|
||||
fx.close
|
||||
|
||||
def on_value1(self, instance, brightness,):
|
||||
self.YV.text = "% d"% brightness
|
||||
fy= open("valueY.txt","w+")
|
||||
fy.write(self.YV.text)
|
||||
fy.close
|
||||
|
||||
def on_value2(self, instance, brightness):
|
||||
self.xlValue.text = "% d"% brightness
|
||||
fxl= open("valueXl.txt","w+")
|
||||
fxl.write(self.xlValue.text)
|
||||
fxl.close
|
||||
|
||||
def on_value3(self, instance, brightness,):
|
||||
self.ylValue.text = "% d"% brightness
|
||||
fyl= open("valueYl.txt","w+")
|
||||
fyl.write(self.ylValue.text)
|
||||
fyl.close
|
||||
|
||||
|
||||
class Eyetrack(App):
|
||||
def build(self):
|
||||
widgetContainer = WidgetContainer()
|
||||
print()
|
||||
|
||||
return widgetContainer
|
||||
|
||||
|
||||
root = Eyetrack()
|
||||
|
||||
|
||||
root.run()
|
||||
Loading…
Reference in New Issue
Block a user