def calibrate(args): np.set_printoptions(precision=4, suppress=True) # Use image path if not explicity specified output_path = args.paths.image_path or args.paths.output_path ws = workspace.Workspace(output_path, args.paths.name) setup_logging(args.runtime.log_level, [ws.log_handler], log_file=path.join(output_path, f"{args.paths.name}.txt")) boards = find_board_config(args.paths.image_path, board_file=args.paths.boards) camera_images = find_camera_images(args.paths.image_path, args.paths.cameras, args.paths.camera_pattern) initialise_with_images(ws, boards, camera_images, args.camera, args.runtime) optimize(ws, args.optimizer) ws.export() ws.dump() if args.vis: visualize_ws(ws)
def calibrate_intrinsic(args): paths = setup_paths(args.paths) setup_logging(args.runtime.log_level, [], log_file=paths.log_file) info(pformat_struct(args)) image_path = os.path.expanduser(args.paths.image_path) info(f"Finding images in {image_path}") camera_images = find_camera_images(image_path, args.paths.cameras, args.paths.camera_pattern, matching=False) image_counts = { k: len(files) for k, files in zip(camera_images.cameras, camera_images.filenames) } info("Found camera directories with images {}".format(image_counts)) board_names, boards = split_dict( find_board_config(image_path, args.paths.boards)) info("Loading images..") images = image.detect.load_images(camera_images.filenames, prefix=camera_images.image_path, j=args.runtime.num_threads) image_sizes = map_list(common_image_size, images) info({ k: image_size for k, image_size in zip(camera_images.cameras, image_sizes) }) cache_key = struct(boards=boards, image_sizes=image_sizes, filenames=camera_images.filenames) detected_points = detect_boards_cached(boards, images, paths.detections, cache_key, j=args.runtime.num_threads) cameras, errs = calibrate_cameras(boards, detected_points, image_sizes, model=args.camera.distortion_model, fix_aspect=args.camera.fix_aspect, has_skew=args.camera.allow_skew, max_images=args.camera.limit_intrinsic) for name, camera, err in zip(camera_images.cameras, cameras, errs): info(f"Calibrated {name}, with RMS={err:.2f}") info(camera) info("") info(f"Writing single calibrations to {paths.calibration_file}") export_single(paths.calibration_file, cameras, camera_images.cameras, camera_images.filenames)
def show_result(args): np.set_printoptions(precision=4, suppress=True) filename = args.workspace_file if path.isdir(filename): filename = path.join(filename, "calibration.pkl") ws = Workspace.load(filename) setup_logging('INFO', [ws.log_handler]) ws.load_images() visualize(ws)
def initialise(args, paths): ws = workspace.Workspace() setup_logging(args.log_level, [ws.log_handler], log_file=paths.log_file) info(args) board_file = args.boards or path.join(args.image_path, "boards.yaml") if args.boards is None: assert path.isfile(board_file),\ f"either specify boards description file with --boards or add boards.yaml to image path" else: assert path.isfile(args.boards), f"board file {args.boards} not found" boards = board.load_config(board_file) info("Using boards:") for name, b in boards.items(): info(f"{name} {b}") cameras = map_none(str.split, args.cameras, ",") ws.find_images_matching(args.image_path, cameras, args.camera_pattern, master = args.master) ws.load_images(j=args.j) ws.detect_boards(boards, cache_file=paths.detection_cache, load_cache=not args.no_cache, j=args.j) ws.calibrate_single(args.distortion_model, fix_aspect=args.fix_aspect, has_skew=args.allow_skew, max_images=args.intrinsic_images) motion_model = None if args.motion_model == "rolling": motion_model = RollingFrames elif args.motion_model == "static": motion_model = StaticFrames else: assert False, f"unknown motion model {args.motion_model}, (static|rolling)" ws.initialise_poses(motion_model=motion_model) return ws