Ejemplo n.º 1
0
def main():
    """
    Let user tune all images in the input folder and report chosen values.

    Load a calibration from file and instantiate a ``BlockMatcher`` of the type
    requested by the user. Load images successively from input folder and
    display their resultant disparity map generated with the ``BlockMatcher``
    and the parameters chosen in the ``BMTuner``'s GUI. Afterwards, report
    user's chosen settings and, if a file for the BM settings is provided, save
    the most common settings to file.
    """
    parser = ArgumentParser(
        description="Read images taken from a calibrated "
        "stereo pair, compute disparity maps from them and "
        "show them interactively to the user, allowing the "
        "user to tune the stereo block matcher settings in "
        "the GUI.",
        parents=[STEREO_SGBM_FLAG])
    parser.add_argument(
        "calibration_folder",
        help="Directory where calibration files for the stereo "
        "pair are stored.")
    parser.add_argument("image_folder",
                        help="Directory where input images are stored.")
    parser.add_argument("--bm_settings",
                        help="File to save last block matcher settings to.",
                        default="")
    args = parser.parse_args()

    calibration = StereoCalibration(input_folder=args.calibration_folder)
    input_files = find_files(args.image_folder)
    if args.use_stereobm:
        block_matcher = StereoBM()
    else:
        block_matcher = StereoSGBM()
    image_pair = [cv2.imread(image) for image in input_files[:2]]
    input_files = input_files[2:]
    rectified_pair = calibration.rectify(image_pair)
    tuner = BMTuner(block_matcher, calibration, rectified_pair)

    while input_files:
        image_pair = [cv2.imread(image) for image in input_files[:2]]
        rectified_pair = calibration.rectify(image_pair)
        tuner.tune_pair(rectified_pair)
        input_files = input_files[2:]

    for param in block_matcher.parameter_maxima:
        print("{}\n".format(tuner.report_settings(param)))

    if args.bm_settings:
        block_matcher.save_settings(args.bm_settings)
Ejemplo n.º 2
0
def main():
    """
    Let user tune all images in the input folder and report chosen values.

    Load a calibration from file and instantiate a ``BlockMatcher`` of the type
    requested by the user. Load images successively from input folder and
    display their resultant disparity map generated with the ``BlockMatcher``
    and the parameters chosen in the ``BMTuner``'s GUI. Afterwards, report
    user's chosen settings and, if a file for the BM settings is provided, save
    the most common settings to file.
    """
    parser = ArgumentParser(description="Read images taken from a calibrated "
                           "stereo pair, compute disparity maps from them and "
                           "show them interactively to the user, allowing the "
                           "user to tune the stereo block matcher settings in "
                           "the GUI.", parents=[STEREO_SGBM_FLAG])
    parser.add_argument("calibration_folder",
                        help="Directory where calibration files for the stereo "
                        "pair are stored.")
    parser.add_argument("image_folder",
                        help="Directory where input images are stored.")
    parser.add_argument("--bm_settings",
                        help="File to save last block matcher settings to.",
                        default="")
    args = parser.parse_args()

    calibration = StereoCalibration(input_folder=args.calibration_folder)
    input_files = find_files(args.image_folder)
    if args.use_stereobm:
        block_matcher = StereoBM()
    else:
        block_matcher = StereoSGBM()
    image_pair = [cv2.imread(image) for image in input_files[:2]]
    input_files = input_files[2:]
    rectified_pair = calibration.rectify(image_pair)
    tuner = BMTuner(block_matcher, calibration, rectified_pair)

    while input_files:
        image_pair = [cv2.imread(image) for image in input_files[:2]]
        rectified_pair = calibration.rectify(image_pair)
        tuner.tune_pair(rectified_pair)
        input_files = input_files[2:]

    for param in block_matcher.parameter_maxima:
        print("{}\n".format(tuner.report_settings(param)))

    if args.bm_settings:
        block_matcher.save_settings(args.bm_settings)
Ejemplo n.º 3
0
def main():
    """
    Take a pictures with chessboard visible to both cameras in a stereo pair.
    """
    parser = argparse.ArgumentParser(description=PROGRAM_DESCRIPTION,
                                parents=[calibrate_stereo.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.ProgressBar(maxval=args.num_pictures,
                                       widgets=[progressbar.Bar("=", "[", "]"),
                                                " ", progressbar.Percentage()])
    if not os.path.exists(args.output_folder):
        os.makedirs(args.output_folder)
    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 = calibrate_stereo.find_files(args.output_folder)
        args.output_folder = args.calibration_folder
        args.show_chessboards = True
        calibrate_stereo.calibrate_folder(args)