Search in sources :

Example 76 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestImplCensusTransformInner method sample_S64.

void sample_S64(Method m) throws InvocationTargetException, IllegalAccessException {
    Class inputType = m.getParameterTypes()[0];
    ImageGray input = GeneralizedImageOps.createSingleBand(inputType, w, h);
    GrayS64 found = new GrayS64(w, h);
    GrayS64 expected = new GrayS64(w, h);
    fillUniform(input);
    int r = 3;
    DogArray<Point2D_I32> samples = createSamples(r);
    DogArray_I32 indexes = samplesToIndexes(input, samples);
    m.invoke(null, input, r, indexes, found);
    CensusNaive.sample(input, samples, expected);
    BoofTesting.assertEqualsInner(expected, found, 0, r, r, r, r, false);
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32) DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 77 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class CreateFiducialSquareHamming method callRenderPdf.

@Override
protected void callRenderPdf(CreateFiducialDocumentPDF renderer) throws IOException {
    DogArray_I32 markerIDs = createMarkerIDs();
    ((CreateSquareHammingDocumentPDF) renderer).render(markerIDs);
}
Also used : CreateSquareHammingDocumentPDF(boofcv.app.fiducials.CreateSquareHammingDocumentPDF) DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 78 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class ExampleMultiViewSparseReconstruction method visualizeSparseCloud.

/**
 * To visualize the results we will render a sparse point cloud along with the location of each camera in the
 * scene.
 */
public void visualizeSparseCloud() {
    checkTrue(scene.isHomogenous());
    List<Point3D_F64> cloudXyz = new ArrayList<>();
    Point4D_F64 world = new Point4D_F64();
    // NOTE: By default the colors found below are not used. Look before to see why and how to turn them on.
    // 
    // Colorize the cloud by reprojecting the images. The math is straight forward but there's a lot of book
    // keeping that needs to be done due to the scene data structure. A class is provided to make this process easy
    var imageLookup = new LookUpImageFilesByIndex(imageFiles);
    var colorize = new ColorizeMultiViewStereoResults<>(new LookUpColorRgbFormats.PL_U8(), imageLookup);
    DogArray_I32 rgb = new DogArray_I32();
    rgb.resize(scene.points.size);
    colorize.processScenePoints(scene, // String encodes the image's index
    (viewIdx) -> viewIdx + "", // Assign the RGB color
    (pointIdx, r, g, b) -> rgb.set(pointIdx, (r << 16) | (g << 8) | b));
    // Convert the structure into regular 3D points from homogenous
    for (int i = 0; i < scene.points.size; i++) {
        scene.points.get(i).get(world);
        // array would be out of sync. Let's just throw it far far away then.
        if (world.w == 0.0)
            cloudXyz.add(new Point3D_F64(0, 0, Double.MAX_VALUE));
        else
            cloudXyz.add(new Point3D_F64(world.x / world.w, world.y / world.w, world.z / world.w));
    }
    PointCloudViewer viewer = VisualizeData.createPointCloudViewer();
    viewer.setFog(true);
    // We just did a bunch of work to look up the true color of points, however for sparse data it's easy to see
    // the structure with psuedo color. Comment out the line below to see the true color.
    viewer.setColorizer(new TwoAxisRgbPlane.Z_XY(1.0).fperiod(40));
    viewer.setDotSize(1);
    viewer.setTranslationStep(0.15);
    viewer.addCloud((idx, p) -> p.setTo(cloudXyz.get(idx)), rgb::get, rgb.size);
    viewer.setCameraHFov(UtilAngle.radian(60));
    SwingUtilities.invokeLater(() -> {
        // Show where the cameras are
        BoofSwingUtil.visualizeCameras(scene, viewer);
        // Size the window and show it to the user
        viewer.getComponent().setPreferredSize(new Dimension(600, 600));
        ShowImages.showWindow(viewer.getComponent(), "Refined Scene", true);
        var copy = new DogArray<>(Point3dRgbI_F64::new);
        viewer.copyCloud(copy);
        try (var out = new FileOutputStream("saved_cloud.ply")) {
            PointCloudIO.save3D(PointCloudIO.Format.PLY, PointCloudReader.wrapF64RGB(copy.toList()), true, out);
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) LookUpColorRgbFormats(boofcv.core.image.LookUpColorRgbFormats) ArrayList(java.util.ArrayList) DogArray_I32(org.ddogleg.struct.DogArray_I32) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) DogArray(org.ddogleg.struct.DogArray) ColorizeMultiViewStereoResults(boofcv.alg.mvs.ColorizeMultiViewStereoResults) FileOutputStream(java.io.FileOutputStream) PointCloudViewer(boofcv.visualize.PointCloudViewer) Point3dRgbI_F64(boofcv.struct.Point3dRgbI_F64) Point4D_F64(georegression.struct.point.Point4D_F64) LookUpImageFilesByIndex(boofcv.io.image.LookUpImageFilesByIndex)

Example 79 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class ExampleSegmentSuperpixels method visualize.

/**
 * Visualizes results three ways. 1) Colorized segmented image where each region is given a random color.
 * 2) Each pixel is assigned the mean color through out the region. 3) Black pixels represent the border
 * between regions.
 */
public static <T extends ImageBase<T>> void visualize(GrayS32 pixelToRegion, T color, int numSegments) {
    // Computes the mean color inside each region
    ImageType<T> type = color.getImageType();
    ComputeRegionMeanColor<T> colorize = FactorySegmentationAlg.regionMeanColor(type);
    var segmentColor = new ColorQueue_F32(type.getNumBands());
    segmentColor.resize(numSegments);
    var regionMemberCount = new DogArray_I32();
    regionMemberCount.resize(numSegments);
    ImageSegmentationOps.countRegionPixels(pixelToRegion, numSegments, regionMemberCount.data);
    colorize.process(color, pixelToRegion, regionMemberCount, segmentColor);
    // Draw each region using their average color
    BufferedImage outColor = VisualizeRegions.regionsColor(pixelToRegion, segmentColor, null);
    // Draw each region by assigning it a random color
    BufferedImage outSegments = VisualizeRegions.regions(pixelToRegion, numSegments, null);
    // Make region edges appear red
    var outBorder = new BufferedImage(color.width, color.height, BufferedImage.TYPE_INT_RGB);
    ConvertBufferedImage.convertTo(color, outBorder, true);
    VisualizeRegions.regionBorders(pixelToRegion, 0xFF0000, outBorder);
    // Show the visualization results
    var gui = new ListDisplayPanel();
    gui.addImage(outColor, "Color of Segments");
    gui.addImage(outBorder, "Region Borders");
    gui.addImage(outSegments, "Regions");
    ShowImages.showWindow(gui, "Superpixels", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) ColorQueue_F32(boofcv.struct.feature.ColorQueue_F32) DogArray_I32(org.ddogleg.struct.DogArray_I32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 80 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class ExampleMultiViewDenseReconstruction method saveCloudToDisk.

private static void saveCloudToDisk(SparseSceneToDenseCloud<GrayU8> sparseToDense) {
    // Save the dense point cloud to disk in PLY format
    try (FileOutputStream out = new FileOutputStream("saved_cloud.ply")) {
        // Filter points which are far away to make it easier to view in 3rd party viewers that auto scale
        // You might need to adjust the threshold for your application if too many points are cut
        double distanceThreshold = 50.0;
        List<Point3D_F64> cloud = sparseToDense.getCloud();
        DogArray_I32 colorsRgb = sparseToDense.getColorRgb();
        DogArray<Point3dRgbI_F64> filtered = PointCloudUtils_F64.filter((idx, p) -> p.setTo(cloud.get(idx)), colorsRgb::get, cloud.size(), (idx) -> cloud.get(idx).norm() <= distanceThreshold, null);
        PointCloudIO.save3D(PointCloudIO.Format.PLY, PointCloudReader.wrapF64RGB(filtered.toList()), true, out);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) FileOutputStream(java.io.FileOutputStream) Point3dRgbI_F64(boofcv.struct.Point3dRgbI_F64) DogArray_I32(org.ddogleg.struct.DogArray_I32) IOException(java.io.IOException)

Aggregations

DogArray_I32 (org.ddogleg.struct.DogArray_I32)192 Test (org.junit.jupiter.api.Test)73 Point2D_I32 (georegression.struct.point.Point2D_I32)24 ArrayList (java.util.ArrayList)21 Point2D_F64 (georegression.struct.point.Point2D_F64)17 DogArray (org.ddogleg.struct.DogArray)17 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)15 GrayS32 (boofcv.struct.image.GrayS32)10 VerbosePrint (org.ddogleg.struct.VerbosePrint)7 View (boofcv.alg.structure.PairwiseImageGraph.View)6 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)6 GrayI (boofcv.struct.image.GrayI)5 Point3D_F64 (georegression.struct.point.Point3D_F64)5 GrowArray (pabeles.concurrency.GrowArray)5 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)4 BTrack (boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack)4 AssociatedTripleIndex (boofcv.struct.feature.AssociatedTripleIndex)4 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)3 SceneWorkingGraph (boofcv.alg.structure.SceneWorkingGraph)3 ConfigAssociateGreedy (boofcv.factory.feature.associate.ConfigAssociateGreedy)3