def main(): """Produce PLY point clouds from stereo image pair.""" parser = argparse.ArgumentParser(description="Read images taken with " "stereo pair and use them to produce 3D " "point clouds that can be viewed with " "MeshLab.", parents=[STEREO_SGBM_FLAG]) parser.add_argument("calibration", help="Path to calibration folder.") parser.add_argument("left", help="Path to left image") parser.add_argument("right", help="Path to right image") parser.add_argument("output", help="Path to output file.") parser.add_argument("--bm_settings", help="Path to block matcher's settings.") args = parser.parse_args() image_pair = [cv2.imread(image) for image in [args.left, args.right]] calibration_folder = args.calibration if args.use_stereobm: block_matcher = StereoBM() else: block_matcher = StereoSGBM() if args.bm_settings: block_matcher.load_settings(args.bm_settings) cp = CalibratedPair(None, StereoCalibration(input_folder=calibration_folder), block_matcher) rectified_pair = cp.calibration.rectify(image_pair) points = cp.get_point_cloud(rectified_pair) points = points.filter_infinity() points.write_ply(args.output)
def main(): """Produce PLY point clouds from stereo image pair.""" parser = argparse.ArgumentParser(description="Read images taken with " "stereo pair and use them to produce 3D " "point clouds that can be viewed with " "MeshLab.", parents=[STEREO_SGBM_FLAG]) parser.add_argument("calibration", help="Path to calibration folder.") parser.add_argument("left", help="Path to left image") parser.add_argument("right", help="Path to right image") parser.add_argument("output", help="Path to output file.") parser.add_argument("--bm_settings", help="Path to block matcher's settings.") args = parser.parse_args() image_pair = [cv2.imread(image) for image in [args.left, args.right]] calibration_folder = args.calibration if args.use_stereobm: block_matcher = StereoBM() else: block_matcher = StereoSGBM() if args.bm_settings: block_matcher.load_settings(args.bm_settings) cp = CalibratedPair(None, StereoCalibration(input_folder=calibration_folder), block_matcher) rectified_pair = cp.calibration.rectify(image_pair) points = cp.get_point_cloud(rectified_pair) points = points.filter_infinity() points.write_ply(args.output)
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)
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)
def main(): 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_BM_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)