basic csv logging done

This commit is contained in:
Prohurtz 2024-06-03 11:10:26 -05:00
parent 759e92171b
commit db654f0327
6 changed files with 556 additions and 550 deletions

View File

@ -10,7 +10,7 @@ from osc import EyeId
import cv2
from winsound import PlaySound, SND_FILENAME, SND_ASYNC
import traceback
import numpy as np
class CameraWidget:
def __init__(self, widget_id: EyeId, main_config: EyeTrackConfig, osc_queue: Queue):
@ -313,8 +313,12 @@ class CameraWidget:
graph.update(background_color="white")
try:
x_real = np.real(eye_info.x)
y_real = np.real(eye_info.y)
# Draw the circle using the real values
graph.draw_circle(
(eye_info.x * -100, eye_info.y * -100),
(x_real * -100, y_real * -100),
25,
fill_color="black",
line_color="white",

View File

@ -50,7 +50,7 @@ def main():
# Check to see if we can connect to our video source first. If not, bring up camera finding
# dialog.
appversion = "0.1.7.2"
appversion = "0.1.8.1-csv-log"
url = "https://raw.githubusercontent.com/RedHawk989/EyeTrackVR-Installer/master/Version-Data/Version_Num.txt"
html = urlopen(url).read()
soup = BeautifulSoup(html, features="html.parser")

View File

@ -20,7 +20,7 @@ class OneEuroFilter:
self.beta = np.full(x0.shape, beta)
self.d_cutoff = np.full(x0.shape, d_cutoff)
# Previous values.
self.x_prev = x0.astype(np.float)
self.x_prev = x0.astype(float)
self.dx_prev = np.full(x0.shape, dx0)
self.t_prev = time()

View File

@ -6,6 +6,7 @@ import queue
import threading
from enum import IntEnum
import time
import csv
class EyeId(IntEnum):
RIGHT = 0
@ -14,6 +15,17 @@ class EyeId(IntEnum):
SETTINGS = 3
from config import EyeTrackConfig
start_time_millis = int(round(time.time() * 1000))
def log_eye_data(eye_id, x, y, eyelid_expanded_squeeze):
print('LOG')
# Calculate the elapsed time since start_time_millis
time_elapsed_millis = int(round(time.time() * 1000)) - start_time_millis
with open('eye_data.csv', mode='a', newline='') as file:
writer = csv.writer(file)
# Include the elapsed time in milliseconds in the row
writer.writerow([time_elapsed_millis, eye_id, x, y, eyelid_expanded_squeeze])
class VRChatOSC:
# Use a tuple of blink (true, blinking, false, not), x, y for now. Probably clearer as a class but
# we're stuck in python 3.6 so still no dataclasses. God I hate python.
@ -46,110 +58,11 @@ class VRChatOSC:
continue
if not eye_info.blink:
if self.config.tracker_single_eye == 1 or self.config.tracker_single_eye == 2:
self.client.send_message("/avatar/parameters/LeftEyeX", eye_info.x) # only one eye is detected or there is an error. Send mirrored data to both eyes.
self.client.send_message("/avatar/parameters/RightEyeX", eye_info.x)
self.client.send_message("/avatar/parameters/EyesY", eye_info.y)
self.client.send_message("/avatar/parameters/RightEyeLid", float(0))# old param open right
self.client.send_message("/avatar/parameters/RightEyeLidExpandedSqueeze", float(0.8)) # open r
self.client.send_message("/avatar/parameters/LeftEyeLid", float(0))# old param open left
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(0.8)) # open left eye
if self.config.gui_blink_sync and not rb and not lb:
self.client.send_message("/avatar/parameters/RightEyeLid", float(0))# old param open right
self.client.send_message("/avatar/parameters/RightEyeLidExpandedSqueeze", float(0.8)) # open r
self.client.send_message("/avatar/parameters/LeftEyeLid", float(0))# old param open left
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(0.8)) # open left eye
else:
if eye_id in [EyeId.RIGHT]:
yr = eye_info.y
sx = eye_info.x
sy = eye_info.y
rb = False
self.client.send_message("/avatar/parameters/RightEyeX", eye_info.x)
if not self.config.gui_blink_sync or self.config.gui_blink_sync and not lb:
self.client.send_message("/avatar/parameters/RightEyeLid", float(0))# old param open right
self.client.send_message("/avatar/parameters/RightEyeLidExpandedSqueeze", float(0.8)) # open right eye
if eye_id in [EyeId.LEFT]:
yl = eye_info.y
sx = eye_info.x
sy = eye_info.y
lb = False
self.client.send_message("/avatar/parameters/LeftEyeX", eye_info.x)
if not self.config.gui_blink_sync or self.config.gui_blink_sync and not rb:
self.client.send_message("/avatar/parameters/LeftEyeLid", float(0))# old param open left
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(0.8)) # open left eye
if (yr != 621 and yl != 621) and (lb == False and rb == False):
y = (yr + yl) / 2
self.client.send_message("/avatar/parameters/EyesY", y)
else:
print(last_blink)
if self.config.gui_blink_sync:
if eye_id in [EyeId.LEFT]:
lb = True
if eye_id in [EyeId.RIGHT]:
rb = True
if rb == True and lb == True : # If both eyes are closed, blink
if last_blink > 0.5:
for i in range(4):
self.client.send_message("/avatar/parameters/RightEyeLid", float(1)) #close eye
self.client.send_message("/avatar/parameters/LeftEyeLid", float(1))
self.client.send_message("/avatar/parameters/RightEyeLidExpandedSqueeze", float(0)) # close eye
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(0))
last_blink = time.time() - last_blink
else:
if self.config.tracker_single_eye == 1 or self.config.tracker_single_eye == 2:
if last_blink > 0.5:
for i in range(4):
self.client.send_message("/avatar/parameters/RightEyeLid", float(1)) #close eye
self.client.send_message("/avatar/parameters/LeftEyeLid", float(1))
self.client.send_message("/avatar/parameters/RightEyeLidExpandedSqueeze", float(0)) # close eye
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(0))
last_blink = time.time() - last_blink
if not self.config.gui_eye_falloff:
if eye_id in [EyeId.LEFT]:
lb = True
if last_blink > 0.7:
for i in range(5):
self.client.send_message("/avatar/parameters/LeftEyeLid", float(1))
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(0))
last_blink = time.time() - last_blink
if eye_id in [EyeId.RIGHT]:
rb = True
if last_blink > 0.7:
for i in range(5):
self.client.send_message("/avatar/parameters/RightEyeLid", float(1))
self.client.send_message("/avatar/parameters/RightEyeLidExpandedSqueeze", float(0)) # close eye
last_blink = time.time() - last_blink
else:
if eye_id in [EyeId.LEFT]:
lb = True
if eye_id in [EyeId.RIGHT]:
rb = True
if rb or lb: # If one eye closed and fall off is enabled, mirror data
self.client.send_message("/avatar/parameters/LeftEyeX", sx) #Send mirrored data to both eyes.
self.client.send_message("/avatar/parameters/RightEyeX", sx)
self.client.send_message("/avatar/parameters/EyesY", sy)
self.client.send_message("/avatar/parameters/RightEyeLid", float(0))# old param open right
self.client.send_message("/avatar/parameters/RightEyeLidExpandedSqueeze", float(0.8)) # open r
self.client.send_message("/avatar/parameters/LeftEyeLid", float(0))# old param open left
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(0.8)) # open left eye
if rb and lb: # If both eyes are closed, blink
if last_blink > 0.5:
for i in range(4):
self.client.send_message("/avatar/parameters/RightEyeLid", float(1)) #close eye
self.client.send_message("/avatar/parameters/LeftEyeLid", float(1))
self.client.send_message("/avatar/parameters/RightEyeLidExpandedSqueeze", float(0)) # close eye
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(0))
last_blink = time.time() - last_blink
print(eye_info.x)
self.client.send_message("/avatar/parameters/LeftEyeX", float(eye_info.x))
self.client.send_message("/avatar/parameters/RightEyeX", float(eye_info.x))
self.client.send_message("/avatar/parameters/EyesY", float(eye_info.y))
log_eye_data(eye_id, eye_info.x, eye_info.y, 1.0)
class VRChatOSCReceiver:

968
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,13 +10,14 @@ repository = "https://github.com/RedHawk989/EyeTrackVR"
python = "~3.11.0"
python-osc = "^1.8.0"
opencv-python = "^4.6.0.66"
numpy = "^1.23.4"
numpy = "1.23.4"
pye3d = "^0.3.1.post1"
requests = "^2.28.1"
pysimplegui = "^4.60.4"
pysimplegui = "^4.59.0"
pydantic = "^1.10.2"
win10toast_click = "^0.1.2"
beautifulsoup4 = "^4.11.1"
bs4 = "0.0.2"
[tool.poetry.group.dev.dependencies]
black = "^22.10.0"