Search in sources :

Example 1 with ConfigDisparitySGM

use of boofcv.factory.disparity.ConfigDisparitySGM 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 ConfigDisparitySGM

use of boofcv.factory.disparity.ConfigDisparitySGM in project BoofCV by lessthanoptimal.

the class ExampleMultiViewDenseReconstruction method main.

public static void main(String[] args) {
    var example = new ExampleMultiViewSparseReconstruction();
    example.compute("tree_snow_01.mp4", true);
    // example.compute("ditch_02.mp4", true);
    // example.compute("holiday_display_01.mp4", true);
    // example.compute("log_building_02.mp4", true);
    // example.compute("drone_park_01.mp4", false);
    // example.compute("stone_sign.mp4", true);
    // Looks up images based on their index in the file list
    var imageLookup = new LookUpImageFilesByIndex(example.imageFiles);
    // We will use a high level algorithm that does almost all the work for us. It is highly configurable
    // and just about every parameter can be tweaked using its Config. Internal algorithms can be accessed
    // and customize directly if needed. Specifics for how it work is beyond this example but the code
    // is easily accessible.
    // Let's do some custom configuration for this scenario
    var config = new ConfigSparseToDenseCloud();
    config.disparity.approach = ConfigDisparity.Approach.SGM;
    ConfigDisparitySGM configSgm = config.disparity.approachSGM;
    configSgm.validateRtoL = 0;
    configSgm.texture = 0.75;
    configSgm.disparityRange = 250;
    configSgm.paths = ConfigDisparitySGM.Paths.P4;
    configSgm.configBlockMatch.radiusX = 3;
    configSgm.configBlockMatch.radiusY = 3;
    // Create the sparse to dense reconstruction using a factory
    SparseSceneToDenseCloud<GrayU8> sparseToDense = FactorySceneReconstruction.sparseSceneToDenseCloud(config, ImageType.SB_U8);
    // To help make the time go by faster while we wait about 1 to 2 minutes for it to finish, let's print stuff
    sparseToDense.getMultiViewStereo().setVerbose(System.out, BoofMiscOps.hashSet(BoofVerbose.RECURSIVE, BoofVerbose.RUNTIME));
    // To visualize intermediate results we will add a listener. This will show fused disparity images
    sparseToDense.getMultiViewStereo().setListener(new MultiViewStereoFromKnownSceneStructure.Listener<>() {

        @Override
        public void handlePairDisparity(String left, String right, GrayU8 rect0, GrayU8 rect1, GrayF32 disparity, GrayU8 mask, DisparityParameters parameters) {
        // Uncomment to display individual stereo pairs. Commented out by default because it generates
        // a LOT of windows
        // BufferedImage outLeft = ConvertBufferedImage.convertTo(rect0, null);
        // BufferedImage outRight = ConvertBufferedImage.convertTo(rect1, null);
        // 
        // ShowImages.showWindow(new RectifiedPairPanel(true, outLeft, outRight), "Rectification: "+left+" "+right);
        // BufferedImage colorized = VisualizeImageData.disparity(disparity, null, parameters.disparityRange, 0);
        // ShowImages.showWindow(colorized, "Disparity " + left + " " + right);
        }

        @Override
        public void handleFusedDisparity(String name, GrayF32 disparity, GrayU8 mask, DisparityParameters parameters) {
            // You can also do custom filtering of the disparity image in this function. If the line below is
            // uncommented then points which are far away will be marked as invalid
            // PixelMath.operator1(disparity, ( v ) -> v >= 20 ? v : parameters.disparityRange, disparity);
            // Display the disparity for each center view
            BufferedImage colorized = VisualizeImageData.disparity(disparity, null, parameters.disparityRange, 0);
            ShowImages.showWindow(colorized, "Center " + name);
        }
    });
    // It needs a look up table to go from SBA view index to image name. It loads images as needed to perform
    // stereo disparity
    var viewToId = new TIntObjectHashMap<String>();
    BoofMiscOps.forIdx(example.working.listViews, (workIdxI, wv) -> viewToId.put(wv.index, wv.pview.id));
    if (!sparseToDense.process(example.scene, viewToId, imageLookup))
        throw new RuntimeException("Dense reconstruction failed!");
    saveCloudToDisk(sparseToDense);
    // Display the dense cloud
    visualizeInPointCloud(sparseToDense.getCloud(), sparseToDense.getColorRgb(), example.scene);
}
Also used : ConfigDisparitySGM(boofcv.factory.disparity.ConfigDisparitySGM) BufferedImage(java.awt.image.BufferedImage) GrayF32(boofcv.struct.image.GrayF32) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) DisparityParameters(boofcv.alg.mvs.DisparityParameters) ConfigSparseToDenseCloud(boofcv.factory.structure.ConfigSparseToDenseCloud) LookUpImageFilesByIndex(boofcv.io.image.LookUpImageFilesByIndex) GrayU8(boofcv.struct.image.GrayU8) MultiViewStereoFromKnownSceneStructure(boofcv.alg.mvs.MultiViewStereoFromKnownSceneStructure)

Aggregations

ConfigDisparitySGM (boofcv.factory.disparity.ConfigDisparitySGM)2 GrayU8 (boofcv.struct.image.GrayU8)2 ConfigSpeckleFilter (boofcv.abst.disparity.ConfigSpeckleFilter)1 DisparityParameters (boofcv.alg.mvs.DisparityParameters)1 MultiViewStereoFromKnownSceneStructure (boofcv.alg.mvs.MultiViewStereoFromKnownSceneStructure)1 ConfigDisparityBMBest5 (boofcv.factory.disparity.ConfigDisparityBMBest5)1 ConfigSparseToDenseCloud (boofcv.factory.structure.ConfigSparseToDenseCloud)1 ControlPanelDisparityDense (boofcv.gui.controls.ControlPanelDisparityDense)1 LookUpImageFilesByIndex (boofcv.io.image.LookUpImageFilesByIndex)1 GrayF32 (boofcv.struct.image.GrayF32)1 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)1 BufferedImage (java.awt.image.BufferedImage)1