Search in sources :

Example 1 with ConfigSpeckleFilter

use of boofcv.abst.disparity.ConfigSpeckleFilter in project BoofCV by lessthanoptimal.

the class DemoThreeViewControls method addDisparityControls.

private void addDisparityControls() {
    ConfigDisparityBMBest5 configBM = new ConfigDisparityBMBest5();
    ConfigDisparitySGM configSGM = new ConfigDisparitySGM();
    ConfigSpeckleFilter configSpeckle = new ConfigSpeckleFilter();
    configBM.disparityMin = configSGM.disparityMin = 0;
    configBM.disparityRange = configSGM.disparityRange = 200;
    configBM.regionRadiusX = configBM.regionRadiusY = 4;
    configBM.errorType = DisparityError.CENSUS;
    configBM.configCensus.variant = CensusVariants.BLOCK_7_7;
    controlDisparity = new ControlPanelDisparityDense(configBM, configSGM, configSpeckle, GrayU8.class);
    controlDisparity.setListener(this::handleStereoChanged);
}
Also used : ConfigDisparityBMBest5(boofcv.factory.disparity.ConfigDisparityBMBest5) ControlPanelDisparityDense(boofcv.gui.controls.ControlPanelDisparityDense) ConfigDisparitySGM(boofcv.factory.disparity.ConfigDisparitySGM) GrayU8(boofcv.struct.image.GrayU8) ConfigSpeckleFilter(boofcv.abst.disparity.ConfigSpeckleFilter)

Example 2 with ConfigSpeckleFilter

use of boofcv.abst.disparity.ConfigSpeckleFilter in project BoofCV by lessthanoptimal.

the class ExampleStereoDisparitySmoothing method main.

public static void main(String[] args) {
    String calibDir = UtilIO.pathExample("calibration/stereo/Bumblebee2_Chess/");
    String imageDir = UtilIO.pathExample("stereo/");
    StereoParameters param = CalibrationIO.load(new File(calibDir, "stereo.yaml"));
    // load and convert images into a BoofCV format
    BufferedImage origLeft = UtilImageIO.loadImage(imageDir, "chair01_left.jpg");
    BufferedImage origRight = UtilImageIO.loadImage(imageDir, "chair01_right.jpg");
    GrayU8 distLeft = ConvertBufferedImage.convertFrom(origLeft, (GrayU8) null);
    GrayU8 distRight = ConvertBufferedImage.convertFrom(origRight, (GrayU8) null);
    // rectify images
    GrayU8 rectLeft = distLeft.createSameShape();
    GrayU8 rectRight = distRight.createSameShape();
    // Using a previous example, rectify then compute the disparity image
    RectifyCalibrated rectifier = ExampleStereoDisparity.rectify(distLeft, distRight, param, rectLeft, rectRight);
    GrayF32 disparity = ExampleStereoDisparity.denseDisparitySubpixel(rectLeft, rectRight, 5, 10, disparityRange);
    // Let's show the results in a single window before speckle is "removed"
    var gui = new ListDisplayPanel();
    gui.addImage("Before", VisualizeImageData.disparity(disparity, null, disparityRange, 0));
    gui.addItem("Before 3D", ExampleStereoDisparity3D.computeAndShowCloud(param, rectLeft, rectifier, disparity));
    // Here's what we came here for. Time to remove the speckle
    var configSpeckle = new ConfigSpeckleFilter();
    // Two pixels are connected if their disparity is this similar
    configSpeckle.similarTol = 1.0f;
    // probably the most important parameter, speckle size
    configSpeckle.maximumArea.setFixed(200);
    DisparitySmoother<GrayU8, GrayF32> smoother = FactoryStereoDisparity.removeSpeckle(configSpeckle, GrayF32.class);
    smoother.process(rectLeft, disparity, disparityRange);
    gui.addImage("After", VisualizeImageData.disparity(disparity, null, disparityRange, 0));
    gui.addItem("After 3D", ExampleStereoDisparity3D.computeAndShowCloud(param, rectLeft, rectifier, disparity));
    // Notice how in the "After 3D" view the number of randomly floating points is much less?
    ShowImages.showWindow(gui, "Disparity Smoothing", true);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ListDisplayPanel(boofcv.gui.ListDisplayPanel) RectifyCalibrated(boofcv.alg.geo.rectify.RectifyCalibrated) GrayU8(boofcv.struct.image.GrayU8) StereoParameters(boofcv.struct.calib.StereoParameters) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ConfigSpeckleFilter(boofcv.abst.disparity.ConfigSpeckleFilter)

Aggregations

ConfigSpeckleFilter (boofcv.abst.disparity.ConfigSpeckleFilter)2 GrayU8 (boofcv.struct.image.GrayU8)2 RectifyCalibrated (boofcv.alg.geo.rectify.RectifyCalibrated)1 ConfigDisparityBMBest5 (boofcv.factory.disparity.ConfigDisparityBMBest5)1 ConfigDisparitySGM (boofcv.factory.disparity.ConfigDisparitySGM)1 ListDisplayPanel (boofcv.gui.ListDisplayPanel)1 ControlPanelDisparityDense (boofcv.gui.controls.ControlPanelDisparityDense)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 StereoParameters (boofcv.struct.calib.StereoParameters)1 GrayF32 (boofcv.struct.image.GrayF32)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1