mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-11-04 14:39:42 +08:00
bug fix
This commit is contained in:
parent
5578da7c99
commit
0e99fd3f21
@ -1,4 +1,4 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
# -*- mode: py -3.6 ; coding: utf-8 -*-
|
||||
|
||||
|
||||
block_cipher = None
|
||||
|
||||
@ -33,10 +33,10 @@ class VRChatOSC:
|
||||
self.client.send_message("/avatar/parameters/LeftEye", eye_info.x)
|
||||
self.client.send_message("/avatar/parameters/EyesY", eye_info.y)
|
||||
if was_blinking:
|
||||
self.client.send_message("/avatar/parameters/LeftEyeLid", float(1))
|
||||
self.client.send_message("/avatar/parameters/RightEyeLid", float(1))
|
||||
self.client.send_message("/avatar/parameters/LeftEyeLid", float(0))
|
||||
self.client.send_message("/avatar/parameters/RightEyeLid", float(0))
|
||||
was_blinking = False
|
||||
else:
|
||||
self.client.send_message("/avatar/parameters/LeftEyeLid", float(0))
|
||||
self.client.send_message("/avatar/parameters/RightEyeLid", float(0))
|
||||
self.client.send_message("/avatar/parameters/LeftEyeLid", float(1))
|
||||
self.client.send_message("/avatar/parameters/RightEyeLid", float(1))
|
||||
was_blinking = True
|
||||
|
||||
@ -26,7 +26,7 @@ class CameraWidget:
|
||||
self.gui_restart_calibration = f"-RESTARTCALIBRATION{widget_id}-"
|
||||
self.gui_recenter_eye = f"-RECENTEREYE{widget_id}-"
|
||||
self.gui_mode_readout = f"-APPMODE{widget_id}-"
|
||||
self.gui_show_color_image = f"-SHOWCOLORIMAGE{widget_id}-"
|
||||
# self.gui_show_color_image = f"-SHOWCOLORIMAGE{widget_id}-"
|
||||
self.gui_roi_message = f"-ROIMESSAGE{widget_id}-"
|
||||
|
||||
self.osc_queue = osc_queue
|
||||
@ -57,7 +57,7 @@ class CameraWidget:
|
||||
[
|
||||
sg.Text("Threshold"),
|
||||
sg.Slider(
|
||||
range=(0, 100),
|
||||
range=(0, 110),
|
||||
default_value=self.config.threshold,
|
||||
orientation="h",
|
||||
key=self.gui_threshold_slider,
|
||||
@ -84,11 +84,11 @@ class CameraWidget:
|
||||
[
|
||||
sg.Button("Restart Calibration", key=self.gui_restart_calibration),
|
||||
sg.Button("Recenter Eye", key=self.gui_recenter_eye),
|
||||
sg.Checkbox(
|
||||
"Show Color Image:",
|
||||
default=self.config.show_color_image,
|
||||
key=self.gui_show_color_image,
|
||||
),
|
||||
#sg.Checkbox(
|
||||
# "Show Color Image:",
|
||||
# default=self.config.show_color_image,
|
||||
# key=self.gui_show_color_image,
|
||||
#),
|
||||
],
|
||||
[sg.Text("Mode:"), sg.Text("Calibrating", key=self.gui_mode_readout)],
|
||||
[sg.Image(filename="", key=self.gui_tracking_image)],
|
||||
@ -210,9 +210,9 @@ class CameraWidget:
|
||||
self.config.vrc_eye_position_scalar = int(values[self.gui_scalar_slider])
|
||||
changed = True
|
||||
|
||||
if self.config.show_color_image != values[self.gui_show_color_image]:
|
||||
self.config.show_color_image = values[self.gui_show_color_image]
|
||||
changed = True
|
||||
# if self.config.show_color_image != values[self.gui_show_color_image]:
|
||||
# self.config.show_color_image = values[self.gui_show_color_image]
|
||||
# changed = True
|
||||
|
||||
if changed:
|
||||
self.main_config.save()
|
||||
|
||||
@ -12,7 +12,7 @@ import json
|
||||
@dataclass
|
||||
class EyeTrackCameraConfig:
|
||||
threshold: "int" = 0
|
||||
rotation_angle: "int" = 0
|
||||
rotation_angle: "int" = 50
|
||||
roi_window_x: "int" = 0
|
||||
roi_window_y: "int" = 0
|
||||
roi_window_w: "int" = 0
|
||||
@ -20,7 +20,7 @@ class EyeTrackCameraConfig:
|
||||
focal_length: "int" = 30
|
||||
capture_source: "Union[int, str, None]" = None
|
||||
vrc_eye_position_scalar: "int" = 3000
|
||||
show_color_image: "bool" = False
|
||||
#show_color_image: "bool" = False
|
||||
|
||||
|
||||
CONFIG_FILE_NAME = "eyetrack_settings.json"
|
||||
|
||||
@ -198,23 +198,23 @@ class EyeProcessor:
|
||||
def output_images_and_update(
|
||||
self, threshold_image, output_information: EyeInformation
|
||||
):
|
||||
if self.config.show_color_image:
|
||||
image_stack = np.concatenate(
|
||||
(
|
||||
self.current_image,
|
||||
cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR),
|
||||
cv2.cvtColor(threshold_image, cv2.COLOR_GRAY2BGR),
|
||||
),
|
||||
axis=1,
|
||||
)
|
||||
else:
|
||||
image_stack = np.concatenate(
|
||||
(
|
||||
cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR),
|
||||
cv2.cvtColor(threshold_image, cv2.COLOR_GRAY2BGR),
|
||||
),
|
||||
axis=1,
|
||||
)
|
||||
# if self.config.show_color_image:
|
||||
# image_stack = np.concatenate(
|
||||
# (
|
||||
# self.current_image,
|
||||
# cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR),
|
||||
# cv2.cvtColor(threshold_image, cv2.COLOR_GRAY2BGR),
|
||||
# ),
|
||||
# axis=1,
|
||||
# )
|
||||
# else:
|
||||
image_stack = np.concatenate(
|
||||
(
|
||||
cv2.cvtColor(self.current_image_gray, cv2.COLOR_GRAY2BGR),
|
||||
cv2.cvtColor(threshold_image, cv2.COLOR_GRAY2BGR),
|
||||
),
|
||||
axis=1,
|
||||
)
|
||||
self.image_queue_outgoing.put((image_stack, output_information))
|
||||
self.previous_image = self.current_image
|
||||
self.previous_rotation = self.config.rotation_angle
|
||||
@ -258,7 +258,7 @@ class EyeProcessor:
|
||||
# something to do blob tracking on.
|
||||
_, larger_threshold = cv2.threshold(
|
||||
self.current_image_gray,
|
||||
int(self.config.threshold + 25),
|
||||
int(self.config.threshold + 15),
|
||||
255,
|
||||
cv2.THRESH_BINARY,
|
||||
)
|
||||
@ -273,7 +273,7 @@ class EyeProcessor:
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
||||
# define circle
|
||||
try:
|
||||
ht, wd = self.current_image_gray.shape[:2]
|
||||
@ -310,7 +310,7 @@ class EyeProcessor:
|
||||
raise RuntimeError("No contours found for image")
|
||||
except:
|
||||
self.output_images_and_update(
|
||||
larger_threshold, EyeInformation(InformationOrigin.FAILURE, 0, 0, False)
|
||||
larger_threshold, EyeInformation(InformationOrigin.FAILURE, 0, 0, 0, False)
|
||||
)
|
||||
return
|
||||
|
||||
@ -392,7 +392,7 @@ class EyeProcessor:
|
||||
|
||||
self.output_images_and_update(
|
||||
larger_threshold,
|
||||
EyeInformation(InformationOrigin.BLOB, out_x, out_y, w, False),
|
||||
EyeInformation(InformationOrigin.BLOB, out_x, out_y, 0, False),
|
||||
)
|
||||
return
|
||||
self.output_images_and_update(
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
# -*- mode: py -3.6 ; coding: utf-8 -*-
|
||||
|
||||
|
||||
block_cipher = None
|
||||
|
||||
@ -25,11 +25,11 @@ class VRChatOSC:
|
||||
self.client = udp_client.SimpleUDPClient(VRChatOSC.OSC_IP, VRChatOSC.OSC_PORT)
|
||||
self.cancellation_event = cancellation_event
|
||||
self.msg_queue = msg_queue
|
||||
yl = 0
|
||||
yr = 0
|
||||
|
||||
def run(self):
|
||||
# Set blinking status to true when we start, just so we make sure we get to an eyelid open state
|
||||
# no matter what.
|
||||
was_blinking = True
|
||||
|
||||
while True:
|
||||
if self.cancellation_event.is_set():
|
||||
print("Exiting OSC Queue")
|
||||
@ -39,41 +39,55 @@ class VRChatOSC:
|
||||
except queue.Empty:
|
||||
continue
|
||||
# If we're not blinking, set position
|
||||
print(eye_info.blink)
|
||||
if not eye_info.blink:
|
||||
if eye_id in [EyeId.RIGHT, EyeId.BOTH]:
|
||||
self.client.send_message(
|
||||
"/avatar/parameters/RightEye", eye_info.x
|
||||
)
|
||||
self.client.send_message(
|
||||
"/avatar/parameters/EyesDilation", eye_info.pupil_dialation
|
||||
"/avatar/parameters/RightEyeX", eye_info.x
|
||||
)
|
||||
# self.client.send_message(
|
||||
# "/avatar/parameters/EyesDilation", eye_info.pupil_dialation
|
||||
#)
|
||||
if eye_id in [EyeId.LEFT, EyeId.BOTH]:
|
||||
self.client.send_message(
|
||||
"/avatar/parameters/LeftEye", eye_info.x
|
||||
)
|
||||
self.client.send_message(
|
||||
"/avatar/parameters/EyesDilation", eye_info.pupil_dialation
|
||||
"/avatar/parameters/LeftEyeX", eye_info.x
|
||||
)
|
||||
|
||||
|
||||
|
||||
self.client.send_message("/avatar/parameters/EyesY", eye_info.y)
|
||||
if was_blinking:
|
||||
if eye_id in [EyeId.LEFT, EyeId.BOTH]:
|
||||
self.client.send_message(
|
||||
"/avatar/parameters/LeftEyeLid", float(1)
|
||||
)
|
||||
if eye_id in [EyeId.RIGHT, EyeId.BOTH]:
|
||||
self.client.send_message(
|
||||
"/avatar/parameters/RightEyeLid", float(1)
|
||||
)
|
||||
was_blinking = False
|
||||
else:
|
||||
if eye_id in [EyeId.LEFT, EyeId.BOTH]:
|
||||
yl = eye_info.y
|
||||
print('left y', yl)
|
||||
|
||||
if eye_id in [EyeId.RIGHT, EyeId.BOTH]:
|
||||
yr = eye_info.y
|
||||
print('right y', yr)
|
||||
|
||||
try:
|
||||
y = abs((yl + yr) / 2)
|
||||
self.client.send_message("/avatar/parameters/EyesY", y)
|
||||
except:
|
||||
print('Y ERROR')
|
||||
|
||||
if eye_id in [EyeId.LEFT, EyeId.BOTH]:
|
||||
|
||||
self.client.send_message(
|
||||
"/avatar/parameters/LeftEyeLid", float(0)
|
||||
)
|
||||
if eye_id in [EyeId.RIGHT, EyeId.BOTH]:
|
||||
|
||||
self.client.send_message(
|
||||
"/avatar/parameters/RightEyeLid", float(0)
|
||||
)
|
||||
was_blinking = True
|
||||
|
||||
else:
|
||||
if eye_id in [EyeId.LEFT, EyeId.BOTH]:
|
||||
|
||||
self.client.send_message(
|
||||
"/avatar/parameters/LeftEyeLid", float(1)
|
||||
)
|
||||
if eye_id in [EyeId.RIGHT, EyeId.BOTH]:
|
||||
|
||||
self.client.send_message(
|
||||
"/avatar/parameters/RightEyeLid", float(1)
|
||||
)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user