def detect_boards(self, boards, cache_file=None, load_cache=True, j=num_threads()): assert self.boards is None board_names, self.boards = split_dict(boards) self.names = self.names._extend(board=board_names) self.board_colors = make_palette(len(boards)) self.detected_points = self.try_load_detections( cache_file) if load_cache else None if self.detected_points is None: info("Detecting boards..") self.detected_points = image.detect.detect_images(self.boards, self.images, j=j) if cache_file is not None: info(f"Writing detection cache to {cache_file}") self.write_detections(cache_file) self.point_table = tables.make_point_table(self.detected_points, self.boards) info("Detected point counts:") tables.table_info(self.point_table.valid, self.names)
def set_calibration(self, index): with (self.updating): ws = self.workspace assert index < len(ws.calibrations) _, calibs = split_dict(ws.calibrations) self.calibration = calibs[index] self.params_viewer.set_cameras( self.calibration.cameras, tables.inverse(self.calibration.camera_poses.pose_table)) self.viewer_3d.enable(False) if self.controllers is None: self.controllers = struct( moving_cameras=MovingCameras(self.viewer_3d, self.calibration, ws.board_colors), moving_board=MovingBoard(self.viewer_3d, self.calibration, ws.board_colors)) else: for controller in self.controllers.values(): controller.update_calibration(self.calibration) self.setup_view_table(self.calibration) self.viewer_3d.enable(True) self.viewer_3d.fix_camera() self.update_controller()
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 set_metric(self, index, board=None): assert isinstance(index, int) and index < len(self.metric_types) keys, _ = split_dict(self.metric_types) self.metric = keys[index] self.view_table, self.view_table_inl = self.get_metric_tables( self.metric, board) self.cell_color_table = self.make_cell_color_table(board) self.modelReset.emit()
def image_layers(self): layers = OrderedDict() if self.calibration is not None: layers['reprojection'] = "Reprojection" layers['detections'] = "Detections" if self.workspace.pose_table is not None: layers['detected_poses'] = "Detected poses" return split_dict(layers)
def detect_boards(self, boards, load_cache=True, j=cpu_count()): assert self.boards is None, "detect_boards: boards already set" assert self.images is not None, "detect_boards: no images loaded, first use add_camera_images" board_names, self.boards = split_dict(boards) self.names = self.names._extend(board=board_names) self.board_colors = make_palette(len(boards)) cache_key = self.fields("filenames", "boards", "image_sizes") self.detected_points = detect_boards_cached(self.boards, self.images, self.detections_file, cache_key, load_cache, j=j) self.point_table = tables.make_point_table(self.detected_points, self.boards) info("Detected point counts:") tables.table_info(self.point_table.valid, self.names)
def update_calibrations(self, calibrations): with (self.updating): has_calibrations = len(calibrations) > 0 self.tab_3d.setEnabled(has_calibrations) self.cameras_tab.setEnabled(has_calibrations) calib_names, calibs = split_dict(calibrations) self.calibrations_combo.clear() self.calibrations_combo.addItems(calib_names) self.calibrations_combo.setCurrentIndex(len(calibs) - 1) if has_calibrations: self.set_calibration(len(calib_names) - 1) else: self.setup_view_table(None) _, layer_labels = self.image_layers() self.layer_combo.clear() self.layer_combo.addItems(layer_labels) self.update_controller()