Search in sources :

Example 1 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 2 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 3 with DogArray

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

the class PointCloudUtils_F64 method prune.

/**
 * Prunes points from the point cloud if they have very few neighbors
 *
 * @param cloud Point cloud
 * @param minNeighbors Minimum number of neighbors for it to not be pruned
 * @param radius search distance for neighbors
 */
public static void prune(List<Point3D_F64> cloud, int minNeighbors, double radius) {
    if (minNeighbors < 0)
        throw new IllegalArgumentException("minNeighbors must be >= 0");
    NearestNeighbor<Point3D_F64> nn = FactoryNearestNeighbor.kdtree(new KdTreePoint3D_F64());
    NearestNeighbor.Search<Point3D_F64> search = nn.createSearch();
    nn.setPoints(cloud, false);
    DogArray<NnData<Point3D_F64>> results = new DogArray<>(NnData::new);
    // It will always find itself
    minNeighbors += 1;
    // distance is Euclidean squared
    radius *= radius;
    for (int i = cloud.size() - 1; i >= 0; i--) {
        search.findNearest(cloud.get(i), radius, minNeighbors, results);
        if (results.size < minNeighbors) {
            cloud.remove(i);
        }
    }
}
Also used : FactoryNearestNeighbor(org.ddogleg.nn.FactoryNearestNeighbor) NearestNeighbor(org.ddogleg.nn.NearestNeighbor) KdTreePoint3D_F64(georegression.helper.KdTreePoint3D_F64) Point3D_F64(georegression.struct.point.Point3D_F64) NnData(org.ddogleg.nn.NnData) DogArray(org.ddogleg.struct.DogArray) KdTreePoint3D_F64(georegression.helper.KdTreePoint3D_F64)

Example 4 with DogArray

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

the class PointCloudUtils_F64 method filter.

/**
 * Creates a new list of points while filtering out points
 */
public static DogArray<Point3dRgbI_F64> filter(AccessPointIndex<Point3D_F64> accessPoint, AccessColorIndex accessColor, int size, BoofLambdas.FilterInt filter, @Nullable DogArray<Point3dRgbI_F64> output) {
    if (output == null)
        output = new DogArray<>(Point3dRgbI_F64::new);
    output.reset();
    // Guess how much memory is needed
    output.reserve(size / 5);
    Point3dRgbI_F64 p = output.grow();
    for (int pointIdx = 0; pointIdx < size; pointIdx++) {
        if (!filter.keep(pointIdx))
            continue;
        accessPoint.getPoint(pointIdx, p);
        p.rgb = accessColor.getRGB(pointIdx);
        p = output.grow();
    }
    output.removeTail();
    return output;
}
Also used : Point3dRgbI_F64(boofcv.struct.Point3dRgbI_F64) DogArray(org.ddogleg.struct.DogArray)

Example 5 with DogArray

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

the class TestPlyCodec method encode_decode_3DRGB_binary.

@Test
void encode_decode_3DRGB_binary() throws IOException {
    List<Point3dRgbI_F64> expected = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        int r = (10 * i) & 0xFF;
        int g = (28 * i) & 0xFF;
        int b = (58 * i) & 0xFF;
        int rgb = r << 16 | g << 16 | b;
        expected.add(new Point3dRgbI_F64(i * 123.45, i - 1.01, i + 2.34, rgb));
    }
    for (boolean asFloat : new boolean[] { true, false }) {
        DogArray<Point3dRgbI_F64> found = new DogArray<>(Point3dRgbI_F64::new);
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        PlyCodec.saveBinary(PointCloudReader.wrapF64RGB(expected), ByteOrder.BIG_ENDIAN, false, asFloat, output);
        ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
        PlyCodec.read(input, PointCloudWriter.wrapF64RGB(found));
        assertEquals(expected.size(), found.size);
        double tol = asFloat ? UtilEjml.TEST_F32 : UtilEjml.TEST_F64;
        for (int i = 0; i < found.size; i++) {
            assertEquals(0.0, found.get(i).distance(expected.get(i)), tol);
        }
    }
}
Also used : Point3dRgbI_F64(boofcv.struct.Point3dRgbI_F64) ArrayList(java.util.ArrayList) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

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