def validate( g_pool, gazer_class_name, gazer_params, gaze_mapper, pupils_in_validation_range, refs_in_validation_range, ): g_pool.import_runtime_plugins() gazers_by_name = gazer_classes_by_class_name(registered_gazer_classes()) gazer_class = gazers_by_name[gazer_class_name] pupil_list = pupils_in_validation_range ref_list = [ _create_ref_dict(ref, g_pool.capture.frame_size) for ref in refs_in_validation_range ] accuracy_result, precision_result, _ = Accuracy_Visualizer.calc_acc_prec_errlines( g_pool=g_pool, gazer_class=gazer_class, gazer_params=gazer_params, pupil_list=pupil_list, ref_list=ref_list, intrinsics=g_pool.capture.intrinsics, outlier_threshold=gaze_mapper.validation_outlier_threshold_deg, ) return accuracy_result, precision_result
def _map_gaze( gazer_class_name, gazer_params, fake_gpool, pupil_pos_in_mapping_range, manual_correction_x, manual_correction_y, shared_memory, ): fake_gpool.import_runtime_plugins() gazers_by_name = gazer_classes_by_class_name(registered_gazer_classes()) gazer_cls = gazers_by_name[gazer_class_name] gazer = gazer_cls(fake_gpool, params=gazer_params) first_ts = pupil_pos_in_mapping_range[0]["timestamp"] last_ts = pupil_pos_in_mapping_range[-1]["timestamp"] ts_span = last_ts - first_ts curr_ts = first_ts for gaze_datum in gazer.map_pupil_to_gaze(pupil_pos_in_mapping_range): _apply_manual_correction(gaze_datum, manual_correction_x, manual_correction_y) # gazer.map_pupil_to_gaze does not yield gaze with monotonic timestamps. # Binocular pupil matches are delayed internally. To avoid non-monotonic # progress updates, we use the largest timestamp that has been returned up to # the current point in time. curr_ts = max(curr_ts, gaze_datum["timestamp"]) shared_memory.progress = (curr_ts - first_ts) / ts_span result = (curr_ts, fm.Serialized_Dict(gaze_datum)) yield [result]
def add(self, calibration, overwrite=False): for calib in self._calibrations.copy(): if calib.unique_id != calibration.unique_id: continue if overwrite: self._calibrations.remove(calib) break logger.warning( f"Did not add calibration {calibration.name} ({calibration.unique_id})" " because it is already in the storage. Currently in storage:\n" + "\n".join(f"- {c.name} ({c.unique_id})" for c in self._calibrations)) return is_calib_editable = (self._from_same_recording(calibration) and calibration.is_offline_calibration) if is_calib_editable: available_gazer_classes = user_selectable_gazer_classes() else: available_gazer_classes = registered_gazer_classes() gazer_class_names = gazer_classes_by_class_name( available_gazer_classes).keys() if calibration.gazer_class_name not in gazer_class_names: logger.warning( f"Did not add calibration {calibration.name} ({calibration.unique_id}) because gaze mapping method ({calibration.gazer_class_name}) is not available." ) return self._calibrations.append(calibration) self._calibrations.sort(key=lambda c: c.name)
def _map_gaze( gazer_class_name, gazer_params, fake_gpool, pupil_pos_in_mapping_range, manual_correction_x, manual_correction_y, shared_memory, ): fake_gpool.import_runtime_plugins() gazers_by_name = gazer_classes_by_class_name(registered_gazer_classes()) gazer_cls = gazers_by_name[gazer_class_name] gazer = gazer_cls(fake_gpool, params=gazer_params) first_ts = pupil_pos_in_mapping_range[0]["timestamp"] last_ts = pupil_pos_in_mapping_range[-1]["timestamp"] ts_span = last_ts - first_ts for gaze_datum in gazer.map_pupil_to_gaze(pupil_pos_in_mapping_range): _apply_manual_correction(gaze_datum, manual_correction_x, manual_correction_y) curr_ts = gaze_datum["timestamp"] shared_memory.progress = (curr_ts - first_ts) / ts_span result = (curr_ts, fm.Serialized_Dict(gaze_datum)) yield [result]
def __gazer_class_from_name(gazer_class_name: str) -> T.Optional[T.Any]: gazers_by_name = gazer_classes_by_class_name(registered_gazer_classes()) try: gazer_cls = gazers_by_name[gazer_class_name] except KeyError: logger.error(f'Unknown gazer "{gazer_class_name}"') return None return gazer_cls
def __gazer_class_from_name(gazer_class_name: str) -> T.Optional[T.Any]: if "HMD" in gazer_class_name: logger.info("Accuracy visualization is disabled for HMD calibration") return None gazers_by_name = gazer_classes_by_class_name(registered_gazer_classes()) try: gazer_cls = gazers_by_name[gazer_class_name] except KeyError: logger.error(f'Unknown gazer "{gazer_class_name}"') return None return gazer_cls
def _create_calibration( fake_gpool, gazer_class_name, ref_dicts_in_calib_range, pupil_pos_in_calib_range ): # This is needed to support user-provided gazers fake_gpool.import_runtime_plugins() gazers_by_name = gazer_classes_by_class_name(registered_gazer_classes()) try: gazer_class = gazers_by_name[gazer_class_name] except KeyError: logger.debug( f"Calibration failed! {gazer_class_name} is not in list of known gazers: " f"{list(gazers_by_name.keys())}" ) status = f"Unknown gazer class: {gazer_class_name}" calibration_result = None return status, calibration_result # Deep copy dicts of pupil positions, to pass to the gazer init pupil_pos_in_calib_range = [p._deep_copy_dict() for p in pupil_pos_in_calib_range] try: calib_data = { "ref_list": ref_dicts_in_calib_range, "pupil_list": pupil_pos_in_calib_range, } gazer = gazer_class( fake_gpool, calib_data=calib_data, raise_calibration_error=True ) calibration_result = model.CalibrationResult( gazer_class_name, gazer.get_params() ) status = "Calibration successful" return status, calibration_result except CalibrationError as err: from traceback import format_exc logger.debug(f"Calibration failed! Traceback:\n{format_exc()}") status = f"Calibration failed: {err.message}" calibration_result = None return status, calibration_result