From cc7df74e7829639805ce0b8554e96f61b54a2576 Mon Sep 17 00:00:00 2001 From: Prohurtz <48768484+RedHawk989@users.noreply.github.com> Date: Sun, 23 Jun 2024 16:36:15 -0500 Subject: [PATCH] feat: 3d calibration now can recive both eye's calib points at a single place in calib3d.py --- EyeTrackApp/camera_widget.py | 1 + EyeTrackApp/config.py | 2 ++ EyeTrackApp/osc_calibrate_filter.py | 17 ++++++++++------- EyeTrackApp/utils/calibration_3d.py | 14 ++++++++------ 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/EyeTrackApp/camera_widget.py b/EyeTrackApp/camera_widget.py index 9c26a50..92bc0d5 100644 --- a/EyeTrackApp/camera_widget.py +++ b/EyeTrackApp/camera_widget.py @@ -63,6 +63,7 @@ class CameraWidget: self.gui_mask_lighten = f"-LIGHTEN{widget_id}-" self.gui_restart_3d_calibration = f"-RESTART3DCALIBRATION{widget_id}-" + self.last_eye_info = None self.osc_queue = osc_queue self.main_config = main_config diff --git a/EyeTrackApp/config.py b/EyeTrackApp/config.py index bbbfcf5..0660c7b 100644 --- a/EyeTrackApp/config.py +++ b/EyeTrackApp/config.py @@ -52,6 +52,8 @@ class EyeTrackCameraConfig(BaseModel): calib_XOFF: Union[float, None] = None calib_YOFF: Union[float, None] = None calibration_points: List[List[Union[float, None]]] = [] + calibration_points_3d: List[List[Union[float, None]]] = [] + class EyeTrackSettingsConfig(BaseModel): diff --git a/EyeTrackApp/osc_calibrate_filter.py b/EyeTrackApp/osc_calibrate_filter.py index 8b7181e..d4ecf59 100644 --- a/EyeTrackApp/osc_calibrate_filter.py +++ b/EyeTrackApp/osc_calibrate_filter.py @@ -187,6 +187,8 @@ class cal: self.calibration_3d_frame_counter = self.calibration_3d_frame_counter - 1 overlay_calibrate_3d(self) + self.config.calibration_points_3d = [] + # print(self.eye_id, cx, cy) # self.settings.gui_3d_calibration = False @@ -197,26 +199,27 @@ class cal: self.settings.grab_3d_point = False var.left_calib = False var.right_calib = False - print('end') + print('end', len(self.config.calibration_points_3d), self.config.calibration_points_3d) + else: # Check if it's the left eye and left calibration is not done yet if self.eye_id == EyeId.LEFT and not var.left_calib: var.left_calib = True - self.config.calibration_points.append((cx, cy, 1)) + self.config.calibration_points_3d.append((cx, cy, 1)) # Check if it's the right eye and right calibration is not done yet elif self.eye_id == EyeId.RIGHT and not var.right_calib: var.right_calib = True - self.config.calibration_points.append((cx, cy, 0)) + self.config.calibration_points_3d.append((cx, cy, 0)) - if self.eye_id == EyeId.LEFT and len(self.config.calibration_points) == 8 and var.left_calib == False: + if self.eye_id == EyeId.LEFT and len(self.config.calibration_points_3d) == 8 and var.left_calib == False: var.left_calib = True - receive_calibration_data(self.config.calibration_points, self.eye_id) + receive_calibration_data(self.config.calibration_points_3d, self.eye_id) print('SENT LEFT EYE POINTS') - if self.eye_id == EyeId.RIGHT and len(self.config.calibration_points) == 8 and var.right_calib == False: + if self.eye_id == EyeId.RIGHT and len(self.config.calibration_points_3d) == 8 and var.right_calib == False: var.right_calib = True - receive_calibration_data(self.config.calibration_points, self.eye_id) + receive_calibration_data(self.config.calibration_points_3d, self.eye_id) print('SENT RIGHT EYE POINTS') # print(len(self.config.calibration_points), self.eye_id) diff --git a/EyeTrackApp/utils/calibration_3d.py b/EyeTrackApp/utils/calibration_3d.py index 8766b58..995b456 100644 --- a/EyeTrackApp/utils/calibration_3d.py +++ b/EyeTrackApp/utils/calibration_3d.py @@ -6,14 +6,16 @@ class CalibrationProcessor: self.right_eye_data = None def receive_calibration_data(self, eye_id, data): - if eye_id == 'left': + if eye_id == 1: self.left_eye_data = data - elif eye_id == 'right': + elif eye_id == 0: self.right_eye_data = data + # print('receive',len(self.left_eye_data), self.left_eye_data, self.right_eye_data, data, eye_id) # Check if both sets of data have been received if self.left_eye_data is not None and self.right_eye_data is not None: - self.process_calibration_data() + if len(self.left_eye_data) == 8 and len(self.right_eye_data) == 8: + self.process_calibration_data() def process_calibration_data(self): # Ensure both data are present @@ -27,12 +29,12 @@ class CalibrationProcessor: print(f"Right Eye Data: {self.right_eye_data}") # After processing, reset the data - self.left_eye_data = None - self.right_eye_data = None + # self.left_eye_data = None + # self.right_eye_data = None # Global instance of CalibrationProcessor calibration_processor = CalibrationProcessor() -def receive_calibration_data(eye_id, data): +def receive_calibration_data(data, eye_id): global calibration_processor calibration_processor.receive_calibration_data(eye_id, data)