Repository: opencv/opencv
File: samples/python/multiview_calibration.py (Python)

Code before:
    parser.add_argument('--path_to_visualize', type=str, default='', help='path to results pickle file needed to run visualization')
    parser.add_argument('--visualize', required=False, action='store_true', help='visualization flag. If set, only runs visualization but path_to_visualize must be provided')
    parser.add_argument('--resize_image_detection', required=False, action='store_true', help='If set, an image will be resized to speed-up corners detection')
    parser.add_argument('--intrinsics', type=str, default=None, help='YAML or XML files with each camera intrinsics')
    parser.add_argument('--gt_file', type=str, default=None, help="ground truth")
    parser.add_argument('--board_dict_path', type=str, default=None, help="path to parameters of board dictionary")

    params, _ = parser.parse_known_args()
    print("params.board_dict_path:", params.board_dict_path)

    if params.log_level == "verbose":
        cv.setLogLevel(6)
    elif params.log_level == "debug":
        cv.setLogLevel(5)
    elif params.log_level == "info":
        cv.setLogLevel(4)
    elif params.log_level == "warning":
        cv.setLogLevel(3)
    elif params.log_level == "error":
        cv.setLogLevel(2)
    elif params.log_level == "fatal":
        cv.setLogLevel(1)
    elif params.log_level == "silent":
        cv.setLogLevel(0)

    if params.visualize:
        assert os.path.exists(params.path_to_visualize), f'Path to result file does not exist: {params.path_to_visualize}'
        visualizeFromFile(params.path_to_visualize)
        sys.exit(0)

    if params.filenames is None:
        cam_files = sorted(glob.glob('cam_*.txt'))
        params.filenames = ','.join(cam_files)
        print('Found camera filenames:', params.filenames)
        params.is_fisheye = ','.join('0' * len(cam_files))
        print('Fisheye parameters:', params.is_fisheye)  # TODO: Calculate it automatically

    if params.json_file is not None:
        output = calibrateFromJSON(params.json_file, params.find_intrinsics_in_python)
        cam_ids = [str(x) for x in range(len(output['Rs']))]
        output['cam_ids'] = cam_ids
    else:
        print(params.pattern_size)
        if (params.pattern_type is None or params.pattern_size is None or params.pattern_distance is None):
            assert False and 'Either json file or all other parameters must be set'

        # cam_N.txt --> cam_N --> N
        cam_ids = [os.path.splitext(f)[0].split('_')[-1] for f in params.filenames.split(',')]

        output = calibrateFromImages(
            files_with_images=[x.strip() for x in params.filenames.split(',')],

Review comment (bug):
Perhaps we should introduce C++/Python API to change logging level using string values supported by environment (`d`, `D`, `debug`, `DEBUG`?).

Code after:
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--log_level', type=str, choices=('', 'verbose', 'debug', 'info', 'warning', 'error', 'fatal', 'silent'), help='OpenCV log level to print more calibration process details')
    parser.add_argument('--json_file', type=str, default=None, help="json file with all data. Must have keys: 'object_points', 'image_points', 'image_sizes', 'is_fisheye'")
    parser.add_argument('--filenames', type=str, default=None, help='Txt files containing image lists, e.g., cam_1.txt,cam_2.txt,...,cam_N.txt for N cameras')
    parser.add_argument('--pattern_size', type=str, default=None, help='pattern size: width,height')
    parser.add_argument('--pattern_type', type=str, default=None, help='supported: checkerboard, circles, acircles, charuco')
    parser.add_argument('--is_fisheye', type=str, default=None, help='is_ mask, e.g., 0,1,...')
    parser.add_argument('--pattern_distance', type=float, default=None, help='distance between object / pattern points')
    parser.add_argument('--find_intrinsics_in_python', required=False, action='store_true', help='calibrate intrinsics in Python sample instead of built-in version')
    parser.add_argument('--use_stereo_init', required=False, action='store_true', help='use calibrateStereo instead of registerCameras for initial pairs registration')
    parser.add_argument('--winsize', type=str, default='5,5', help='window size for corners detection: w,h')
    parser.add_argument('--debug_corners', required=False, action='store_true', help='debug flag for corners detection visualization of images')
    parser.add_argument('--points_json_file', type=str, default='', help='if path is provided then image and object points will be saved to JSON file.')
    parser.add_argument('--path_to_save', type=str, default='', help='path and filename to save results in yaml file')
    parser.add_argument('--path_to_visualize', type=str, default='', help='path to results pickle file needed to run visualization')
    parser.add_argument('--visualize', required=False, action='store_true', help='visualization flag. If set, only runs visualization but path_to_visualize must be provided')
    parser.add_argument('--resize_image_detection', required=False, action='store_true', help='If set, an image will be resized to speed-up corners detection')
    parser.add_argument('--intrinsics', type=str, default=None, help='YAML or XML files with each camera intrinsics')
    parser.add_argument('--gt_file', type=str, default=None, help="ground truth")
    parser.add_argument('--board_dict_path', type=str, default=None, help="path to parameters of board dictionary")

    params, _ = parser.parse_known_args()
    print("params.board_dict_path:", params.board_dict_path)

    if params.log_level == "verbose":
        cv.setLogLevel(6)
    elif params.log_level == "debug":
        cv.setLogLevel(5)
    elif params.log_level == "info":
        cv.setLogLevel(4)
    elif params.log_level == "warning":
        cv.setLogLevel(3)
    elif params.log_level == "error":
        cv.setLogLevel(2)
    elif params.log_level == "fatal":
        cv.setLogLevel(1)
    elif params.log_level == "silent":
        cv.setLogLevel(0)

    if params.visualize:
        assert os.path.exists(params.path_to_visualize), f'Path to result file does not exist: {params.path_to_visualize}'
        visualizeFromFile(params.path_to_visualize)
        sys.exit(0)

    if params.filenames is None:
        cam_files = sorted(glob.glob('cam_*.txt'))
        params.filenames = ','.join(cam_files)
        print('Found camera filenames:', params.filenames)
        params.is_fisheye = ','.join('0' * len(cam_files))
        print('Fisheye parameters:', params.is_fisheye)  # TODO: Calculate it automatically