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);
}
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);
}
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;
}
Aggregations