Пример #1
0
def f(errors_by_every_file_path, allowable_error):
    from trem_researcher import TremResearcher
    import numpy as np

    _researcher = TremResearcher(marks_num=5, marks_size_mm=10)

    folders_to_check = [
        r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 3\X 0',
        r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 3\X 15',
        r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 3\X 30',
        r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 3\X 45',
        r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 3\X 60',
        r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 3\X 75',
        r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 3\Y 0',
        r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 3\Y 15',
        r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 3\Y 30',
        r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 3\Y 45',
        r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 3\Y 60',
        r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 3\Y 75'
    ]

    with open((errors_by_every_file_path), 'rb') as file:
        errors = pickle.load(file)

    files_to_calib = []
    for file in errors:
        errors_for_file = np.asarray(
            [np.mean(errors[file][folder]) for folder in errors[file]])
        is_allowable_error = np.abs(errors_for_file) < allowable_error
        if list(is_allowable_error).count(True) == len(is_allowable_error):
            files_to_calib += [file]

    if len(files_to_calib) == 0:
        return {
            allowable_error: {folder: np.nan
                              for folder in folders_to_check}
        }

    print(
        f"Calibrate sample with allowable_error={allowable_error}. Started.\n")
    _researcher.calibrate(images_paths=files_to_calib)
    print(
        f"Calibrate sample with allowable_error={allowable_error}. Finished.\n"
    )

    FRAMES_PER_STEP = 5
    STEP_MM = 5
    get_errors = _researcher.get_errors_finder(
        frames_per_step=FRAMES_PER_STEP,
        step_mm=STEP_MM,
        text_for_log=
        f'Find errors for subsample with allowable error:{allowable_error}.')

    _res = {
        allowable_error: {
            folder: get_errors(_researcher.photo_files(folder))
            for folder in folders_to_check
        }
    }
    return _res
Пример #2
0
def f(calib_images_path, i):
    from trem_researcher import TremResearcher
    import numpy as np
    import cv2
    _researcher = TremResearcher(marks_num=5, marks_size_mm=10)
    calib_images = _researcher.photo_files(calib_images_path)

    FRAMES_PER_STEP = 5
    STEP_MM = 5

    # folders_to_check = [r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 2\X',
    #                     r'D:\Projects\Tremor\Calibration\Check calibration photo\Focus distance 50 mm 2\Y']
    folders_to_check = [
        fr'..{sep}Calibration{sep}Check calibration photo{sep}Focus distance 50 mm 3{sep}X 0',
        fr'..{sep}Calibration{sep}Check calibration photo{sep}Focus distance 50 mm 3{sep}X 15',
        fr'..{sep}Calibration{sep}Check calibration photo{sep}Focus distance 50 mm 3{sep}X 30',
        fr'..{sep}Calibration{sep}Check calibration photo{sep}Focus distance 50 mm 3{sep}X 45',
        fr'..{sep}Calibration{sep}Check calibration photo{sep}Focus distance 50 mm 3{sep}X 60',
        fr'..{sep}Calibration{sep}Check calibration photo{sep}Focus distance 50 mm 3{sep}Y 0',
        fr'..{sep}Calibration{sep}Check calibration photo{sep}Focus distance 50 mm 3{sep}Y 15',
        fr'..{sep}Calibration{sep}Check calibration photo{sep}Focus distance 50 mm 3{sep}Y 30',
        fr'..{sep}Calibration{sep}Check calibration photo{sep}Focus distance 50 mm 3{sep}Y 45',
        fr'..{sep}Calibration{sep}Check calibration photo{sep}Focus distance 50 mm 3{sep}Y 60'
    ]

    print(f"Calibrate with {i} file. Started.")
    _researcher.calibrate(images_paths=[calib_images[i]])
    print(f"Calibrate with {i} file. Finished.")

    get_errors = _researcher.get_errors_finder(
        frames_per_step=FRAMES_PER_STEP,
        step_mm=STEP_MM,
        text_for_log=f'Find errors for {calib_images[i]}.')

    return {
        calib_images[i]: {
            folder: get_errors(_researcher.photo_files(folder))
            for folder in folders_to_check
        }
    }