Search in sources :

Example 36 with DogArray

use of org.ddogleg.struct.DogArray 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 37 with DogArray

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

the class PointCloudViewerSwing method copyCloud.

@Override
public DogArray<Point3dRgbI_F64> copyCloud(@Nullable DogArray<Point3dRgbI_F64> copy) {
    if (copy == null)
        copy = new DogArray<>(Point3dRgbI_F64::new);
    else
        copy.reset();
    DogArray<Point3dRgbI_F64> _copy = copy;
    // See if it has color information on the points or not
    final PackedArray<Point3D_F32> cloudXyz = panel.getCloudXyz();
    final BigDogArray_I32 cloudColor = panel.getCloudColor();
    synchronized (cloudXyz) {
        if (cloudXyz.size() == cloudColor.size) {
            cloudXyz.forIdx(0, cloudXyz.size(), (idx, point) -> _copy.grow().setTo(point.x, point.y, point.z, cloudColor.get(idx)));
        } else {
            cloudXyz.forIdx(0, cloudXyz.size(), (idx, point) -> _copy.grow().setTo(point.x, point.y, point.z));
        }
    }
    return copy;
}
Also used : Point3D_F32(georegression.struct.point.Point3D_F32) Point3dRgbI_F64(boofcv.struct.Point3dRgbI_F64) BigDogArray_I32(org.ddogleg.struct.BigDogArray_I32) DogArray(org.ddogleg.struct.DogArray)

Example 38 with DogArray

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

the class ShapeFittingOps method convert_I32_F32.

public static DogArray<Point2D_F32> convert_I32_F32(List<Point2D_I32> input, @Nullable DogArray<Point2D_F32> output) {
    if (output == null)
        output = new DogArray<>(input.size(), Point2D_F32::new);
    else
        output.reset();
    for (int i = 0; i < input.size(); i++) {
        Point2D_I32 p = input.get(i);
        output.grow().setTo(p.x, p.y);
    }
    return output;
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32) Point2D_F32(georegression.struct.point.Point2D_F32) DogArray(org.ddogleg.struct.DogArray)

Example 39 with DogArray

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

the class ShapeFittingOps method fitPolygon.

/**
 * <p>Fits a polygon to the provided sequence of connected points. The found polygon is returned as a list of
 * vertices. Each point in the original sequence is guaranteed to be within "toleranceDist' of a line segment.</p>
 *
 * <p>Internally a split-and-merge algorithm is used. See referenced classes for more information. Consider
 * using internal algorithms directly if this function is a performance bottleneck.</p>
 *
 * @param sequence Ordered and connected list of points.
 * @param loop If true the sequence is a connected at both ends, otherwise it is assumed to not be.
 * @param minimumSideLength The minimum allowed side length in pixels. Try 10
 * @param cornerPenalty How much a corner is penalized. Try 0.25
 * @return Vertexes in the fit polygon.
 * @see PolylineSplitMerge
 */
public static List<PointIndex_I32> fitPolygon(List<Point2D_I32> sequence, boolean loop, int minimumSideLength, double cornerPenalty) {
    PolylineSplitMerge alg = new PolylineSplitMerge();
    alg.setLoops(loop);
    alg.setMinimumSideLength(minimumSideLength);
    alg.setCornerScorePenalty(cornerPenalty);
    alg.process(sequence);
    PolylineSplitMerge.CandidatePolyline best = alg.getBestPolyline();
    DogArray<PointIndex_I32> output = new DogArray<>(PointIndex_I32::new);
    if (best != null) {
        indexToPointIndex(sequence, best.splits, output);
    }
    return new ArrayList<>(output.toList());
}
Also used : PointIndex_I32(boofcv.struct.PointIndex_I32) ArrayList(java.util.ArrayList) PolylineSplitMerge(boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge) DogArray(org.ddogleg.struct.DogArray)

Example 40 with DogArray

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

the class TestAssociateGreedyBruteForce2D_MT method createData.

public static DogArray<TupleDesc_F64> createData(int count) {
    Random rand = new Random(234);
    DogArray<TupleDesc_F64> ret = new DogArray<>(count, () -> new TupleDesc_F64(1));
    for (int i = 0; i < count; i++) {
        ret.grow().setTo(rand.nextDouble() * 10);
    }
    return ret;
}
Also used : Random(java.util.Random) TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) DogArray(org.ddogleg.struct.DogArray)

Aggregations

DogArray (org.ddogleg.struct.DogArray)79 Test (org.junit.jupiter.api.Test)48 ArrayList (java.util.ArrayList)27 Point3D_F64 (georegression.struct.point.Point3D_F64)18 DogArray_I32 (org.ddogleg.struct.DogArray_I32)17 Point2D_F64 (georegression.struct.point.Point2D_F64)16 GrayU8 (boofcv.struct.image.GrayU8)13 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)10 Point2D_I32 (georegression.struct.point.Point2D_I32)7 DMatrixRMaj (org.ejml.data.DMatrixRMaj)7 BufferedImage (java.awt.image.BufferedImage)6 Point3dRgbI_F64 (boofcv.struct.Point3dRgbI_F64)5 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)5 List (java.util.List)5 PositionPatternNode (boofcv.alg.fiducial.qrcode.PositionPatternNode)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)4 GrayF32 (boofcv.struct.image.GrayF32)4 PointCloudViewer (boofcv.visualize.PointCloudViewer)4 Se3_F64 (georegression.struct.se.Se3_F64)4 FactoryNearestNeighbor (org.ddogleg.nn.FactoryNearestNeighbor)4