Search in sources :

Example 51 with DogArray

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

the class ShapeFittingOps method convert_I32_F64.

public static DogArray<Point2D_F64> convert_I32_F64(List<Point2D_I32> input, @Nullable DogArray<Point2D_F64> output) {
    if (output == null)
        output = new DogArray<>(input.size(), Point2D_F64::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_F64(georegression.struct.point.Point2D_F64) Point2D_I32(georegression.struct.point.Point2D_I32) DogArray(org.ddogleg.struct.DogArray)

Example 52 with DogArray

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

the class PruneStructureFromSceneMetric method prunePoints.

/**
 * Prune a feature it has fewer than X neighbors within Y distance. Observations
 * associated with this feature are also pruned.
 *
 * Call {@link #pruneViews(int)} to makes sure the graph is valid.
 *
 * @param neighbors Number of other features which need to be near by
 * @param distance Maximum distance a point can be to be considered a feature
 */
public void prunePoints(int neighbors, double distance) {
    // Use a nearest neighbor search to find near by points
    Point3D_F64 worldX = new Point3D_F64();
    List<Point3D_F64> cloud = new ArrayList<>();
    for (int i = 0; i < structure.points.size; i++) {
        SceneStructureCommon.Point structureP = structure.points.data[i];
        structureP.get(worldX);
        cloud.add(worldX.copy());
    }
    NearestNeighbor<Point3D_F64> nn = FactoryNearestNeighbor.kdtree(new KdTreePoint3D_F64());
    NearestNeighbor.Search<Point3D_F64> search = nn.createSearch();
    nn.setPoints(cloud, false);
    DogArray<NnData<Point3D_F64>> resultsNN = new DogArray<>(NnData::new);
    // Create a look up table containing from old to new indexes for each point
    int[] oldToNew = new int[structure.points.size];
    // crash is bug
    Arrays.fill(oldToNew, -1);
    // List of point ID's which are to be removed.
    DogArray_I32 prunePointID = new DogArray_I32();
    // identify points which need to be pruned
    for (int pointId = 0; pointId < structure.points.size; pointId++) {
        SceneStructureCommon.Point structureP = structure.points.data[pointId];
        structureP.get(worldX);
        // distance is squared
        search.findNearest(cloud.get(pointId), distance * distance, neighbors + 1, resultsNN);
        // Don't prune if it has enough neighbors. Remember that it will always find itself.
        if (resultsNN.size() > neighbors) {
            oldToNew[pointId] = pointId - prunePointID.size;
            continue;
        }
        prunePointID.add(pointId);
        // Remove observations of this point
        for (int viewIdx = 0; viewIdx < structureP.views.size; viewIdx++) {
            SceneObservations.View v = observations.getView(structureP.views.data[viewIdx]);
            int pointIdx = v.point.indexOf(pointId);
            if (pointIdx < 0)
                throw new RuntimeException("Bad structure. Point not found in view's observation " + "which was in its structure");
            v.remove(pointIdx);
        }
    }
    pruneUpdatePointID(oldToNew, prunePointID);
}
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_I32(org.ddogleg.struct.DogArray_I32) DogArray(org.ddogleg.struct.DogArray) KdTreePoint3D_F64(georegression.helper.KdTreePoint3D_F64)

Example 53 with DogArray

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

the class TestLinearExternalContours method checkExpectedExternal.

public static void checkExpectedExternal(int[] expected, LinearExternalContours alg) {
    PackedSetsPoint2D_I32 contours = alg.getExternalContours();
    assertEquals(expected.length, contours.size());
    DogArray<Point2D_I32> points = new DogArray<>(Point2D_I32::new);
    boolean[] matched = new boolean[expected.length];
    for (int i = 0; i < expected.length; i++) {
        int e = expected[i];
        boolean foo = false;
        for (int j = 0; j < contours.size(); j++) {
            if (matched[j])
                continue;
            contours.getSet(j, points);
            if (points.size == e) {
                matched[j] = true;
                foo = true;
                break;
            }
        }
        assertTrue(foo);
    }
}
Also used : PackedSetsPoint2D_I32(boofcv.struct.PackedSetsPoint2D_I32) Point2D_I32(georegression.struct.point.Point2D_I32) PackedSetsPoint2D_I32(boofcv.struct.PackedSetsPoint2D_I32) DogArray(org.ddogleg.struct.DogArray)

Example 54 with DogArray

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

the class TestBinaryEllipseDetectorPixel method undistortContour.

/**
 * Undistort the image when no distoriton is provided
 */
@Test
void undistortContour() {
    List<Point2D_I32> input = new ArrayList<>();
    DogArray<Point2D_F64> output = new DogArray<>(Point2D_F64::new);
    for (int i = 0; i < 10; i++) {
        input.add(new Point2D_I32(i, i));
    }
    BinaryEllipseDetectorPixel alg = new BinaryEllipseDetectorPixel();
    alg.undistortContour(input, output);
    assertEquals(input.size(), output.size);
    for (int i = 0; i < input.size(); i++) {
        Point2D_I32 p = input.get(i);
        assertEquals(p.x, output.get(i).x, 1e-8);
        assertEquals(p.y, output.get(i).y, 1e-8);
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 55 with DogArray

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

the class TestMergeSmallRegions method process.

/**
 * Runs everything to remove the small patches. This test hsa been designed to take multiple
 * passes to complete.
 */
@Test
void process() {
    GrayU8 image = new GrayU8(10, 9);
    image.data = new byte[] { 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 7, 8, 0, 0, 0, 0, 0, 5, 6, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 0, 0, 0, 7, 0, 0, 0, 5, 5, 4, 4, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 0, 0, 0, 0, 0, 0, 9, 9, 6, 7 };
    GrayS32 pixelToRegion = new GrayS32(10, 9);
    pixelToRegion.data = new int[] { 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 4, 5, 0, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 9, 0, 0, 0, 1, 1, 3, 3, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 6, 6, 7, 8 };
    DogArray_I32 memberCount = new DogArray_I32();
    memberCount.resize(10);
    for (int i = 0; i < pixelToRegion.data.length; i++) {
        memberCount.data[pixelToRegion.data[i]]++;
    }
    DogArray<float[]> regionColor = new DogArray<>(() -> new float[1]);
    regionColor.resize(10);
    ComputeRegionMeanColor<GrayU8> mean = new ComputeRegionMeanColor.U8();
    mean.process(image, pixelToRegion, memberCount, regionColor);
    MergeSmallRegions<GrayU8> alg = new MergeSmallRegions<>(3, ConnectRule.FOUR, mean);
    alg.process(image, pixelToRegion, memberCount, regionColor);
    // check the results. Should only be three regions
    assertEquals(3, memberCount.size);
    assertEquals(3, regionColor.size);
    DogArray_I32 memberExpected = new DogArray_I32(3);
    memberExpected.resize(3);
    for (int i = 0; i < pixelToRegion.data.length; i++) {
        memberExpected.data[pixelToRegion.data[i]]++;
    }
    for (int i = 0; i < 3; i++) assertEquals(memberExpected.get(i), memberCount.get(i));
    // simple sanity check
    assertTrue(memberExpected.get(0) > memberExpected.get(1));
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrayU8(boofcv.struct.image.GrayU8) DogArray_I32(org.ddogleg.struct.DogArray_I32) GrayS32(boofcv.struct.image.GrayS32) 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