Example #1
0
def calibrate_and_map(g_pool, ref_list, calib_list, map_list, x_offset,
                      y_offset):
    yield "calibrating", []
    method, result = select_calibration_method(g_pool, calib_list, ref_list)
    if result['subject'] != 'calibration.failed':
        logger.info(
            'Offline calibration successful. Starting mapping using {}.'.
            format(method))
        name, args = result['name'], result['args']
        gaze_mapper_cls = gaze_mapping_plugins_by_name[name]
        gaze_mapper = gaze_mapper_cls(g_pool, **args)

        for idx, datum in enumerate(map_list):
            mapped_gaze = gaze_mapper.on_pupil_datum(datum)

            # apply manual correction
            for gp in mapped_gaze:
                # gp['norm_pos'] is a tuple by default
                gp_norm_pos = list(gp['norm_pos'])
                gp_norm_pos[1] += y_offset
                gp_norm_pos[0] += x_offset
                gp['norm_pos'] = gp_norm_pos

            if mapped_gaze:
                progress = (100 * (idx + 1) / len(map_list))
                progress = "Mapping..{}%".format(int(progress))
                yield progress, mapped_gaze
        progress = "Mapping complete."
        yield progress, []
    else:
        yield "calibration failed", []
Example #2
0
def _create_calibration(fake_gpool, ref_dicts_in_calib_range, pupil_pos_in_calib_range):
    method, result = select_calibration_method(
        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
Example #3
0
def _create_calibration(fake_gpool, ref_dicts_in_calib_range,
                        pupil_pos_in_calib_range):
    method, result = select_calibration_method(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
Example #4
0
def calibrate_and_map(g_pool, ref_list, calib_list, map_list):
    method, result = select_calibration_method(g_pool, calib_list, ref_list)
    if result['subject'] != 'calibration.failed':
        logger.info(
            'Offline calibration successful. Starting mapping using {}.'.
            format(method))
        name, args = result['name'], result['args']
        gaze_mapper_cls = gaze_mapping_plugins_by_name[name]
        gaze_mapper = gaze_mapper_cls(Empty(), **args)

        for idx, datum in enumerate(map_list):
            mapped_gaze = gaze_mapper.on_pupil_datum(datum)
            if mapped_gaze:
                progress = (100 * (idx + 1) / len(map_list))
                if progress == 100:
                    progress = "Mapping complete."
                else:
                    progress = "Mapping..{}%".format(int(progress))
                yield progress, mapped_gaze
Example #5
0
def calibrate_and_map(g_pool, ref_list, calib_list, map_list):
    yield "calibrating",[]
    method, result = select_calibration_method(g_pool, calib_list, ref_list)
    if result['subject'] != 'calibration.failed':
        logger.info('Offline calibration successful. Starting mapping using {}.'.format(method))
        name, args = result['name'], result['args']
        gaze_mapper_cls = gaze_mapping_plugins_by_name[name]
        gaze_mapper = gaze_mapper_cls(Empty(), **args)

        for idx, datum in enumerate(map_list):
            mapped_gaze = gaze_mapper.on_pupil_datum(datum)
            if mapped_gaze:
                progress = (100 * (idx+1)/len(map_list))
                if progress == 100:
                    progress = "Mapping complete."
                else:
                    progress = "Mapping..{}%".format(int(progress))
                yield progress, mapped_gaze
    else:
        yield "calibration failed",[]
Example #6
0
def calibrate_and_map(g_pool, ref_list, calib_list, map_list, x_offset,
                      y_offset):
    yield "calibrating", []
    calib_list = [
        msgpack.unpackb(serialized, raw=False, use_list=False)
        for serialized in calib_list
    ]
    method, result = select_calibration_method(g_pool, calib_list, ref_list)
    if result["subject"] != "calibration.failed":
        logger.info(
            "Offline calibration successful. Starting mapping using {}.".
            format(method))
        name, args = result["name"], result["args"]
        gaze_mapper_cls = gaze_mapping_plugins_by_name[name]
        gaze_mapper = gaze_mapper_cls(g_pool, **args)

        for idx_incoming, serialized in enumerate(map_list):
            datum = msgpack.unpackb(serialized, raw=False, use_list=False)
            mapped_gaze = gaze_mapper.on_pupil_datum(datum)

            # apply manual correction
            for idx_outgoing, gaze_datum in enumerate(mapped_gaze):
                # gp['norm_pos'] is a tuple by default
                gaze_norm_pos = list(gaze_datum["norm_pos"])
                gaze_norm_pos[1] += y_offset
                gaze_norm_pos[0] += x_offset
                gaze_datum["norm_pos"] = gaze_norm_pos
                serialized = msgpack.packb(gaze_datum, use_bin_type=True)
                mapped_gaze[idx_outgoing] = gaze_datum["timestamp"], serialized

            if mapped_gaze:
                progress = 100 * (idx_incoming + 1) / len(map_list)
                progress = "Mapping..{}%".format(int(progress))
                yield progress, mapped_gaze
        progress = "Mapping complete."
        yield progress, []
    else:
        # logger does not work here, because we are in a subprocess
        fail_message = "Calibration failed: {}".format(result["reason"])
        print(fail_message, len(calib_list), len(ref_list))
        yield fail_message, []