def main(): """ Read all images in input folder and produce camera calibration files. First, parse arguments provided by user. Then scan input folder for input files. Harvest chessboard points from each image in folder, then use them to calibrate the stereo pair. Report average error to user and export calibration files to output folder. """ parser = ArgumentParser(description="Read images taken with " "stereo pair and use them to compute " "camera calibration.", parents=[CHESSBOARD_ARGUMENTS]) parser.add_argument("input_folder", help="Input folder assumed to contain " "only stereo images taken with the stereo camera pair " "that should be calibrated.") parser.add_argument("output_folder", help="Folder to write calibration " "files to.", default="/tmp/") parser.add_argument("--show-chessboards", help="Display detected " "chessboard corners.", action="store_true") args = parser.parse_args() print(args.input_folder) args.input_files = find_files(args.input_folder) calibrate_folder(args)
def calibrate(self, output_folder='output', calibration_folder='calib'): # Make the calibration step. print('>' * 5 + ' Performing calibration....') parser = argparse.ArgumentParser() args = parser.parse_args() args.rows = 7 args.columns = 9 args.square_size = 2.2 args.input_files = find_files(output_folder) args.output_folder = output_folder args.calibrate_folder = calibrate_folder args.show_chessboards = True calibrate_folder(args)
def main(): parser = ArgumentParser(description=PROGRAM_DESCRIPTION, parents=[CHESSBOARD_ARGUMENTS]) parser.add_argument("left", metavar="left", type=int, help="Device numbers for the left camera.") parser.add_argument("right", metavar="right", type=int, help="Device numbers for the right camera.") parser.add_argument("num_pictures", type=int, help="Number of valid " "chessboard pictures that should be taken.") parser.add_argument("output_folder", help="Folder to save the images to.") parser.add_argument("--calibration-folder", help="Folder to save camera " "calibration to.") args = parser.parse_args() if args.calibration_folder and not args.square_size: args.print_help() progress = ProgressBar(maxval=args.num_pictures, widgets=[Bar("=", "[", "]"), " ", Percentage()]) if not os.path.exists(args.output_folder): os.makedirs(args.output_folder) progress.start() with ChessboardFinder((args.left, args.right)) as pair: for i in range(args.num_pictures): frames = pair.get_chessboard(args.columns, args.rows, True) for side, frame in zip(("left", "right"), frames): number_string = str(i + 1).zfill(len(str(args.num_pictures))) filename = "{}_{}.ppm".format(side, number_string) output_path = os.path.join(args.output_folder, filename) cv2.imwrite(output_path, frame) progress.update(progress.maxval - (args.num_pictures - i)) for i in range(10): pair.show_frames(1) progress.finish() if args.calibration_folder: args.input_files = find_files(args.output_folder) args.output_folder = args.calibration_folder args.show_chessboards = True calibrate_folder(args)
def main(): parser = ArgumentParser(description=PROGRAM_DESCRIPTION, parents=[CHESSBOARD_ARGUMENTS]) parser.add_argument("left", metavar="left", type=int, help="Device numbers for the left camera.") parser.add_argument("right", metavar="right", type=int, help="Device numbers for the right camera.") parser.add_argument("num_pictures", type=int, help="Number of valid " "chessboard pictures that should be taken.") parser.add_argument("output_folder", help="Folder to save the images to.") parser.add_argument("--calibration-folder", help="Folder to save camera " "calibration to.") args = parser.parse_args() if args.calibration_folder and not args.square_size: args.print_help() progress = ProgressBar(maxval=args.num_pictures, widgets=[Bar("=", "[", "]"), " ", Percentage()]) if not os.path.exists(args.output_folder): os.makedirs(args.output_folder) progress.start() with ChessboardFinder((args.left, args.right)) as pair: # Sets initial position of windows, based on image size set_window_position(pair) for i in range(args.num_pictures): # Introduces a 5 second delay before the camera pair is scanned for new images enforce_delay(pair, 5) frames, corners = pair.get_chessboard(args.columns, args.rows, True) for side, frame in zip(("left", "right"), frames): number_string = str(i + 1).zfill(len(str(args.num_pictures))) filename = "{}_{}.ppm".format(side, number_string) output_path = os.path.join(args.output_folder, filename) cv2.imwrite(output_path, frame) progress.update(progress.maxval - (args.num_pictures - i)) # Displays the recent accepted image pair. Helps in generating diverse calibration images. show_selected_frames(frames, corners, pair, args, True) progress.finish() #cv2.destroyAllWindows() if args.calibration_folder: args.input_files = find_files(args.output_folder) args.output_folder = args.calibration_folder args.show_chessboards = True calibrate_folder(args)
input_folder = 'pictures/' class CalibrationInfo: input_files = [ input_folder + '1-1.jpg', input_folder + '1-2.jpg', input_folder + '2-1.jpg', input_folder + '2-2.jpg', input_folder + '3-1.jpg', input_folder + '3-2.jpg', input_folder + '4-1.jpg', input_folder + '4-2.jpg', ] def __init__(self, rows=9, columns=6, square_size=2.3, output_folder="calibration", show_chessboards=False): self.rows = rows self.columns = columns self.square_size = square_size self.output_folder = output_folder self.show_chessboards = show_chessboards calibrate_folder(CalibrationInfo())