mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-11-04 14:39:42 +08:00
cleaning
This commit is contained in:
parent
7836a5022b
commit
5c0b1b45fd
@ -115,9 +115,7 @@ class Camera:
|
|||||||
if should_push:
|
if should_push:
|
||||||
self.push_image_to_queue(image, frame_number, fps)
|
self.push_image_to_queue(image, frame_number, fps)
|
||||||
except:
|
except:
|
||||||
print(
|
print("\033[93m[INFO] Capture source problem, assuming camera disconnected, waiting for reconnect.\033[0m")
|
||||||
"Capture source problem, assuming camera disconnected, waiting for reconnect."
|
|
||||||
)
|
|
||||||
self.camera_status = CameraState.DISCONNECTED
|
self.camera_status = CameraState.DISCONNECTED
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -160,8 +158,7 @@ class Camera:
|
|||||||
print(ex)
|
print(ex)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(ex.__class__)
|
print(ex.__class__)
|
||||||
print(
|
print("\033[93m[INFO]Serial capture source problem, assuming camera disconnected, waiting for reconnect.\033[0m")
|
||||||
"Serial capture source problem, assuming camera disconnected, waiting for reconnect.")
|
|
||||||
self.camera_status = CameraState.DISCONNECTED
|
self.camera_status = CameraState.DISCONNECTED
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -188,6 +185,6 @@ class Camera:
|
|||||||
# some sort of capture event conflict though.
|
# some sort of capture event conflict though.
|
||||||
qsize = self.camera_output_outgoing.qsize()
|
qsize = self.camera_output_outgoing.qsize()
|
||||||
if qsize > 1:
|
if qsize > 1:
|
||||||
print(f"\033[91mCAPTURE QUEUE BACKPRESSURE OF {qsize}. CHECK FOR CRASH OR TIMING ISSUES IN ALGORITHM.\033[0m")
|
print(f"\033[91m[WARN] CAPTURE QUEUE BACKPRESSURE OF {qsize}. CHECK FOR CRASH OR TIMING ISSUES IN ALGORITHM.\033[0m")
|
||||||
self.camera_output_outgoing.put((image, frame_number, fps))
|
self.camera_output_outgoing.put((image, frame_number, fps))
|
||||||
self.capture_event.clear()
|
self.capture_event.clear()
|
||||||
|
|||||||
@ -69,7 +69,7 @@ def u16_3ch_to_u32_1ch(img):
|
|||||||
|
|
||||||
|
|
||||||
def newdata(frameshape):
|
def newdata(frameshape):
|
||||||
print("Initialise data for blinking.")
|
print("\033[94m[INFO] Initialise data for blinking.\033[0m")
|
||||||
return np.zeros(frameshape, dtype=np.uint32)
|
return np.zeros(frameshape, dtype=np.uint32)
|
||||||
|
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ class IntensityBasedOpeness:
|
|||||||
# Not very clever, but increase the width by 1px to save the maximum value.
|
# Not very clever, but increase the width by 1px to save the maximum value.
|
||||||
frameshape = (frameshape[0], frameshape[1] + 1)
|
frameshape = (frameshape[0], frameshape[1] + 1)
|
||||||
if self.data is None:
|
if self.data is None:
|
||||||
print("Load data for blinking: {}".format(self.imgfile))
|
print(f"\033[92m[INFO] Loaded data for blinking: {self.imgfile}\033[0m")
|
||||||
if os.path.isfile(self.imgfile):
|
if os.path.isfile(self.imgfile):
|
||||||
try:
|
try:
|
||||||
img = cv2.imread(self.imgfile, flags=cv2.IMREAD_UNCHANGED)
|
img = cv2.imread(self.imgfile, flags=cv2.IMREAD_UNCHANGED)
|
||||||
@ -116,16 +116,16 @@ class IntensityBasedOpeness:
|
|||||||
else:
|
else:
|
||||||
self.maxval = self.data[0, -1]
|
self.maxval = self.data[0, -1]
|
||||||
except:
|
except:
|
||||||
print("File read error: {}".format(self.imgfile))
|
print("[ERROR] File read error: {}".format(self.imgfile))
|
||||||
req_newdata = True
|
req_newdata = True
|
||||||
else:
|
else:
|
||||||
print("File does not exist.")
|
print("\033[94m[INFO] File does not exist.\033[0m")
|
||||||
req_newdata = True
|
req_newdata = True
|
||||||
else:
|
else:
|
||||||
if self.data.shape != frameshape or not np.array_equal(self.img_roi, self.now_roi):
|
if self.data.shape != frameshape or not np.array_equal(self.img_roi, self.now_roi):
|
||||||
# If the ROI recorded in the image file differs from the current ROI
|
# If the ROI recorded in the image file differs from the current ROI
|
||||||
#todo: Using the previous and current frame sizes and centre positions from the original, etc., the data can be ported to some extent, but there may be many areas where code changes are required.
|
#todo: Using the previous and current frame sizes and centre positions from the original, etc., the data can be ported to some extent, but there may be many areas where code changes are required.
|
||||||
print("Frame size changed.")
|
print("[INFO] \033[94mFrame size changed.\033[0m")
|
||||||
req_newdata = True
|
req_newdata = True
|
||||||
if req_newdata:
|
if req_newdata:
|
||||||
self.data = newdata(frameshape)
|
self.data = newdata(frameshape)
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
from pythonosc import udp_client
|
from pythonosc import udp_client
|
||||||
from pythonosc import osc_server
|
from pythonosc import osc_server
|
||||||
from pythonosc import dispatcher
|
from pythonosc import dispatcher
|
||||||
import sys
|
|
||||||
from utils.misc_utils import PlaySound,SND_FILENAME,SND_ASYNC
|
from utils.misc_utils import PlaySound,SND_FILENAME,SND_ASYNC
|
||||||
import queue
|
import queue
|
||||||
import threading
|
import threading
|
||||||
@ -35,7 +34,6 @@ def output_osc(eye_x, eye_y, eye_blink, last_blink, self):
|
|||||||
for i in range(5):
|
for i in range(5):
|
||||||
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(self.l_eye_blink))
|
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(self.l_eye_blink))
|
||||||
last_blink = time.time() - last_blink
|
last_blink = time.time() - last_blink
|
||||||
|
|
||||||
if self.config.gui_eye_falloff:
|
if self.config.gui_eye_falloff:
|
||||||
if self.r_eye_blink == 0.0: #if both eyes closed and DEF is enables, blink
|
if self.r_eye_blink == 0.0: #if both eyes closed and DEF is enables, blink
|
||||||
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(self.l_eye_blink))
|
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(self.l_eye_blink))
|
||||||
@ -57,7 +55,6 @@ def output_osc(eye_x, eye_y, eye_blink, last_blink, self):
|
|||||||
for i in range(5):
|
for i in range(5):
|
||||||
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(self.r_eye_blink))
|
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(self.r_eye_blink))
|
||||||
last_blink = time.time() - last_blink
|
last_blink = time.time() - last_blink
|
||||||
|
|
||||||
if self.config.gui_eye_falloff:
|
if self.config.gui_eye_falloff:
|
||||||
if self.l_eye_blink == 0.0: #if both eyes closed and DEF is enables, blink
|
if self.l_eye_blink == 0.0: #if both eyes closed and DEF is enables, blink
|
||||||
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(self.r_eye_blink))
|
self.client.send_message("/avatar/parameters/LeftEyeLidExpandedSqueeze", float(self.r_eye_blink))
|
||||||
@ -75,7 +72,6 @@ def output_osc(eye_x, eye_y, eye_blink, last_blink, self):
|
|||||||
self.client.send_message("/avatar/parameters/EyesY", y)
|
self.client.send_message("/avatar/parameters/EyesY", y)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VRChatOSC:
|
class VRChatOSC:
|
||||||
# Use a tuple of blink (true, blinking, false, not), x, y for now.
|
# Use a tuple of blink (true, blinking, false, not), x, y for now.
|
||||||
def __init__(self, cancellation_event: threading.Event, msg_queue: queue.Queue[tuple[bool, int, int]], main_config: EyeTrackConfig,):
|
def __init__(self, cancellation_event: threading.Event, msg_queue: queue.Queue[tuple[bool, int, int]], main_config: EyeTrackConfig,):
|
||||||
@ -92,7 +88,6 @@ class VRChatOSC:
|
|||||||
self.r_eye_blink = 0.7
|
self.r_eye_blink = 0.7
|
||||||
self.l_eye_blink = 0.7
|
self.l_eye_blink = 0.7
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
start = time.time()
|
start = time.time()
|
||||||
@ -108,7 +103,6 @@ class VRChatOSC:
|
|||||||
|
|
||||||
output_osc(eye_info.x, eye_info.y, eye_info.blink, last_blink, self)
|
output_osc(eye_info.x, eye_info.y, eye_info.blink, last_blink, self)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VRChatOSCReceiver:
|
class VRChatOSCReceiver:
|
||||||
def __init__(self, cancellation_event: threading.Event, main_config: EyeTrackConfig, eyes: []):
|
def __init__(self, cancellation_event: threading.Event, main_config: EyeTrackConfig, eyes: []):
|
||||||
@ -152,4 +146,4 @@ class VRChatOSCReceiver:
|
|||||||
self.server.serve_forever()
|
self.server.serve_forever()
|
||||||
|
|
||||||
except:
|
except:
|
||||||
print(f"\033[91m[ERROR] OSC Recieve port: {self.config.gui_osc_receiver_port} occupied.\033[0m")
|
print(f"\033[91m[ERROR] OSC Recieve port: {self.config.gui_osc_receiver_port} occupied.\033[0m")
|
||||||
Loading…
Reference in New Issue
Block a user