From 6b171393d77c31508e6be96389a1519810b66370 Mon Sep 17 00:00:00 2001 From: Prohurtz <48768484+RedHawk989@users.noreply.github.com> Date: Wed, 21 Dec 2022 10:19:44 -0800 Subject: [PATCH] fix blob --- EyeTrackApp/camera_widget.py | 25 ++++++++++++++------ EyeTrackApp/eye_processor.py | 46 +++++++++++++++--------------------- EyeTrackApp/osc.py | 1 - 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/EyeTrackApp/camera_widget.py b/EyeTrackApp/camera_widget.py index ab9af74..f0d75f1 100644 --- a/EyeTrackApp/camera_widget.py +++ b/EyeTrackApp/camera_widget.py @@ -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): @@ -314,12 +314,23 @@ class CameraWidget: graph.update(background_color="white") #try: - graph.draw_circle( - (eye_info.x * -100, eye_info.y * -100), - 25, - fill_color="black", - line_color="white", - ) + print(eye_info.x, eye_info.y) + if not np.isnan(eye_info.x) and not np.isnan(eye_info.y): + + graph.draw_circle( + (eye_info.x * -100, eye_info.y * -100), + 25, + fill_color="black", + line_color="white", + ) + else: + + graph.draw_circle( + (0.0 * -100, 0.0 * -100), + 25, + fill_color="black", + line_color="white", + ) # except: # pass elif eye_info.blink: diff --git a/EyeTrackApp/eye_processor.py b/EyeTrackApp/eye_processor.py index 491ccee..414ae02 100644 --- a/EyeTrackApp/eye_processor.py +++ b/EyeTrackApp/eye_processor.py @@ -989,6 +989,7 @@ class EyeProcessor: except: pass def BLOB(self): + # define circle if self.config.gui_circular_crop: if self.cct == 0: @@ -1013,31 +1014,24 @@ class EyeProcessor: else: self.cct = self.cct - 1 _, larger_threshold = cv2.threshold(self.current_image_gray, int(self.config.threshold + 12), 255, cv2.THRESH_BINARY) - # Blob tracking requires that we have a vague idea of where the eye may be at the moment. This - # means we need to have had at least one successful runthrough of the Pupil Labs algorithm in - # order to have a projected sphere. - if self.lkg_projected_sphere == None: - self.output_images_and_update( - larger_threshold, EyeInformation(InformationOrigin.FAILURE, 0, 0, 0, False) - ) - return + - try: + #try: # Try rebuilding our contours - contours, _ = cv2.findContours( - larger_threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE - ) - contours = sorted(contours, key=lambda x: cv2.contourArea(x), reverse=True) - # If we have no contours, we have nothing to blob track. Fail here. - if len(contours) == 0: - raise RuntimeError("No contours found for image") - except: - self.output_images_and_update( - larger_threshold, EyeInformation(InformationOrigin.FAILURE, 0, 0, 0, False) - ) - return + contours, _ = cv2.findContours( + larger_threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE + ) + contours = sorted(contours, key=lambda x: cv2.contourArea(x), reverse=True) + + # If we have no contours, we have nothing to blob track. Fail here. + if len(contours) == 0: + raise RuntimeError("No contours found for image") + # except: + # self.output_images_and_update(larger_threshold, EyeInformation(InformationOrigin.FAILURE, 0, 0, 0, False)) + # return rows, cols = larger_threshold.shape + for cnt in contours: (x, y, w, h) = cv2.boundingRect(cnt) @@ -1047,13 +1041,11 @@ class EyeProcessor: if not self.settings.gui_blob_minsize <= h <= self.settings.gui_blob_maxsize or not self.settings.gui_blob_minsize <= w <= self.settings.gui_blob_maxsize: continue - + cx = x + int(w / 2) cy = y + int(h / 2) - xrlb = (cx - self.lkg_projected_sphere["center"][0]) / self.lkg_projected_sphere["axes"][0] - eyeyb = (cy - self.lkg_projected_sphere["center"][1]) / self.lkg_projected_sphere["axes"][1] cv2.line( self.current_image_gray, (x + int(w / 2), 0), @@ -1498,13 +1490,13 @@ class EyeProcessor: self.current_image_gray = cv2.cvtColor( self.current_image, cv2.COLOR_BGR2GRAY ) - print(self.settings.gui_RANSAC3D) + # print(self.settings.gui_RANSAC3D) try: #This is flawed currently, i will come up with a better system soon if self.settings.gui_RANSAC3D == True: #for now ransac goes first f == self.RANSAC3D() - if f and self.settings.gui_HSF == True: #if a fail has been reported and other algo is enabled, use it. + if self.settings.gui_HSF == True: #if a fail has been reported and other algo is enabled, use it. f == self.HSF() - if f and self.settings.gui_BLOB == True: + if self.settings.gui_BLOB == True: f == self.BLOB() except: pass diff --git a/EyeTrackApp/osc.py b/EyeTrackApp/osc.py index 0ab8b1d..90af94f 100644 --- a/EyeTrackApp/osc.py +++ b/EyeTrackApp/osc.py @@ -85,7 +85,6 @@ class VRChatOSC: 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