Search in sources :

Example 41 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap 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)

Example 42 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project spf4j by zolyfarkas.

the class Converter method convert.

@Nullable
public static SampleNode convert(final Iterator<StackSampleElement> samples) {
    TIntObjectMap<SampleNode> index = new TIntObjectHashMap<>();
    while (samples.hasNext()) {
        StackSampleElement asmp = samples.next();
        SampleNode sn = new SampleNode(asmp.getCount());
        SampleNode parent = index.get(asmp.getParentId());
        if (parent != null) {
            Method m = asmp.getMethod();
            parent.put(m, sn);
        }
        index.put(asmp.getId(), sn);
    }
    return index.get(0);
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) SampleNode(org.spf4j.stackmonitor.SampleNode) Method(org.spf4j.base.avro.Method) StackSampleElement(org.spf4j.base.avro.StackSampleElement) Nullable(javax.annotation.Nullable)

Example 43 with TIntObjectHashMap

use of gnu.trove.map.hash.TIntObjectHashMap in project spf4j by zolyfarkas.

the class Converter method loadSamples.

// it's a private method, don't care about being generic
@SuppressFBWarnings("OCP_OVERLY_CONCRETE_PARAMETER")
private static TIntObjectMap<SampleNode> loadSamples(final Decoder decoder, final StackSampleElement pasmp, final SpecificDatumReader<StackSampleElement> reader) throws IOException {
    TIntObjectMap<SampleNode> index = new TIntObjectHashMap<>();
    long nrArrayItems = decoder.readArrayStart();
    while (nrArrayItems > 0) {
        for (int j = 0; j < nrArrayItems; j++) {
            StackSampleElement asmp = reader.read(pasmp, decoder);
            SampleNode sn = new SampleNode(asmp.getCount());
            SampleNode parent = index.get(asmp.getParentId());
            if (parent != null) {
                Method readMethod = asmp.getMethod();
                Method m = new Method(readMethod.getDeclaringClass(), readMethod.getName());
                parent.put(m, sn);
            }
            index.put(asmp.getId(), sn);
        }
        nrArrayItems = decoder.arrayNext();
    }
    return index;
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) SampleNode(org.spf4j.stackmonitor.SampleNode) Method(org.spf4j.base.avro.Method) StackSampleElement(org.spf4j.base.avro.StackSampleElement) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)43 ArrayList (java.util.ArrayList)15 LinkedList (java.util.LinkedList)13 PeakResultPoint (uk.ac.sussex.gdsc.smlm.results.PeakResultPoint)12 List (java.util.List)11 Coordinate (uk.ac.sussex.gdsc.core.match.Coordinate)10 Ticker (uk.ac.sussex.gdsc.core.logging.Ticker)9 MemoryPeakResults (uk.ac.sussex.gdsc.smlm.results.MemoryPeakResults)9 TIntHashSet (gnu.trove.set.hash.TIntHashSet)8 IJ (ij.IJ)8 Prefs (ij.Prefs)8 PlugIn (ij.plugin.PlugIn)8 TextWindow (ij.text.TextWindow)8 Arrays (java.util.Arrays)8 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 ImageJUtils (uk.ac.sussex.gdsc.core.ij.ImageJUtils)8 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)8 MathUtils (uk.ac.sussex.gdsc.core.utils.MathUtils)8 TIntProcedure (gnu.trove.procedure.TIntProcedure)7