Search in sources :

Example 21 with DogArray

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

the class TestBinaryEllipseDetectorPixel method undistortContour_WithDistortion.

/**
 * Undistort the image when distortion model is provided
 */
@Test
void undistortContour_WithDistortion() {
    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.setLensDistortion(new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, 10.0f, 0)));
    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 + 10, output.get(i).x, 1e-8);
        assertEquals(p.y, output.get(i).y, 1e-8);
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Affine2D_F32(georegression.struct.affine.Affine2D_F32) ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 22 with DogArray

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

the class GenericFhEdgeWeightsChecks method basicTest.

@Test
void basicTest() {
    T input = imageType.createImage(10, 12);
    GImageMiscOps.fillUniform(input, rand, 0, 200);
    FhEdgeWeights<T> alg = createAlg();
    DogArray<Edge> edges = new DogArray<>(Edge::new);
    alg.process(input, edges);
    int[] hist = new int[input.width * input.height];
    // see if the edges computed the expected weight
    for (int i = 0; i < edges.size(); i++) {
        Edge e = edges.get(i);
        int indexA = e.indexA;
        int indexB = e.indexB;
        hist[indexA]++;
        hist[indexB]++;
        float expected = weight(input, indexA, indexB);
        assertEquals(expected, e.weight(), 1e-4f);
    }
    // make sure each pixel was inspected
    if (rule == ConnectRule.FOUR) {
        for (int y = 0; y < input.height; y++) {
            for (int x = 0; x < input.width; x++) {
                if (x >= 1 && x < input.width - 1 && y >= 1 && y < input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 4);
                else if (x == 0 && y == 0)
                    assertEquals(hist[input.getIndex(x, y)], 2);
                else if (x == input.width - 1 && y == 0)
                    assertEquals(hist[input.getIndex(x, y)], 2);
                else if (x == input.width - 1 && y == input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 2);
                else if (x == 0 && y == input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 2);
                else {
                    assertEquals(hist[input.getIndex(x, y)], 3);
                }
            }
        }
    } else if (rule == ConnectRule.EIGHT) {
        for (int y = 0; y < input.height; y++) {
            for (int x = 0; x < input.width; x++) {
                if (x >= 1 && x < input.width - 1 && y >= 1 && y < input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 8);
                else if (x == 0 && y == 0)
                    assertEquals(hist[input.getIndex(x, y)], 3);
                else if (x == input.width - 1 && y == 0)
                    assertEquals(hist[input.getIndex(x, y)], 3);
                else if (x == input.width - 1 && y == input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 3);
                else if (x == 0 && y == input.height - 1)
                    assertEquals(hist[input.getIndex(x, y)], 3);
                else {
                    assertEquals(hist[input.getIndex(x, y)], 5);
                }
            }
        }
    } else {
        throw new RuntimeException("Unknown rule");
    }
}
Also used : Edge(boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 23 with DogArray

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

the class TestMergeRegionMeanShift method basicAll.

@Test
void basicAll() {
    MergeRegionMeanShift alg = new MergeRegionMeanShift(1, 1);
    GrayS32 pixelToRegion = new GrayS32(4, 4);
    pixelToRegion.data = new int[] { 0, 0, 0, 1, 2, 0, 0, 1, 2, 0, 1, 1, 0, 0, 3, 1 };
    DogArray_I32 regionMemberCount = new DogArray_I32();
    regionMemberCount.data = new int[] { 1, 2, 3, 4 };
    regionMemberCount.size = 4;
    DogArray<float[]> regionColor = createList(5, 1, 6, 4);
    DogArray<Point2D_I32> modeLocation = new DogArray<>(Point2D_I32::new);
    modeLocation.grow().setTo(0, 0);
    modeLocation.grow().setTo(3, 3);
    modeLocation.grow().setTo(0, 1);
    modeLocation.grow().setTo(2, 3);
    alg.process(pixelToRegion, regionMemberCount, regionColor, modeLocation);
    GrayS32 expectedP2R = new GrayS32(4, 4);
    expectedP2R.data = new int[] { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 2, 1 };
    int[] expectedCount = new int[] { 4, 2, 4 };
    for (int i = 0; i < expectedP2R.data.length; i++) assertEquals(expectedP2R.data[i], pixelToRegion.data[i]);
    for (int i = 0; i < expectedCount.length; i++) assertEquals(expectedCount[i], regionMemberCount.data[i]);
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32) DogArray_I32(org.ddogleg.struct.DogArray_I32) GrayS32(boofcv.struct.image.GrayS32) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 24 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 25 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)

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