Exemplo n.º 1
0
 def _load_recorded_calibrations(self):
     notifications = fm.load_pldata_file(self._rec_dir, "notify")
     for topic, data in zip(notifications.topics, notifications.data):
         if topic == "notify.calibration.calibration_data":
             try:
                 calib_result = model.CalibrationResult(
                     mapping_plugin_name=data["mapper_name"],
                     mapper_args=dict(data["mapper_args"]),
                 )
             except KeyError:
                 # notifications from old recordings will not have these fields!
                 continue
             mapping_method = "2d" if "2d" in data[
                 "calibration_method"] else "3d"
             # the unique id needs to be the same at every start or otherwise the
             # same calibrations would be added again and again. The timestamp is
             # the easiest datum that differs between calibrations but is the same
             # for every start
             unique_id = model.Calibration.create_unique_id_from_string(
                 str(data["timestamp"]))
             calibration = model.Calibration(
                 unique_id=unique_id,
                 name=make_unique.by_number_at_end("Recorded Calibration",
                                                   self.item_names),
                 recording_uuid=self._recording_uuid,
                 mapping_method=mapping_method,
                 frame_index_range=self._get_recording_index_range(),
                 minimum_confidence=0.8,
                 is_offline_calibration=False,
                 result=calib_result,
             )
             self.add(calibration)
Exemplo n.º 2
0
def _create_calibration(fake_gpool, ref_dicts_in_calib_range,
                        pupil_pos_in_calib_range):
    method, result = select_method_and_perform_calibration(
        fake_gpool, pupil_pos_in_calib_range, ref_dicts_in_calib_range)

    if result["subject"] == "start_plugin":
        calibration_result = model.CalibrationResult(result["name"],
                                                     result["args"])
        status = "Calibration successful"
    elif result["subject"] == "calibration.failed":
        logger.error("Calibration failed: {}".format(result["reason"]))
        calibration_result = None
        status = result["reason"]
    else:
        logger.error("Unknown calibration result: {}".format(result))
        calibration_result = None
        status = "Unknown calibration result"
    return status, calibration_result
Exemplo n.º 3
0
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