Search in sources :

Example 26 with DogArray_I32

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

the class TestAssociateNearestNeighbor_ST method various.

/**
 * Several tests combined into one
 */
@Test
void various() {
    Dummy<TupleDesc_F64> nn = new Dummy<>();
    // src = assoc[i] where src is the index of the source feature and i is the index of the dst feature
    nn.assoc = new int[] { 2, 0, 1, -1, 4, -1, -1, 2, 2, 1 };
    AssociateNearestNeighbor_ST<TupleDesc_F64> alg = new AssociateNearestNeighbor_ST<>(nn, TupleDesc_F64.class);
    FastArray<TupleDesc_F64> src = new FastArray<>(TupleDesc_F64.class);
    FastArray<TupleDesc_F64> dst = new FastArray<>(TupleDesc_F64.class);
    for (int i = 0; i < 5; i++) {
        src.add(new TupleDesc_F64(10));
    }
    for (int i = 0; i < 10; i++) {
        dst.add(new TupleDesc_F64(10));
    }
    alg.setSource(src);
    alg.setDestination(dst);
    alg.associate();
    DogArray<AssociatedIndex> matches = alg.getMatches();
    assertEquals(7, matches.size);
    for (int i = 0, count = 0; i < nn.assoc.length; i++) {
        if (nn.assoc[i] != -1) {
            int source = nn.assoc[i];
            assertEquals(source, matches.get(count).src);
            assertEquals(i, matches.get(count).dst);
            count++;
        }
    }
    DogArray_I32 unassoc = alg.getUnassociatedSource();
    assertEquals(1, unassoc.size);
    assertEquals(3, unassoc.get(0));
    unassoc = alg.getUnassociatedDestination();
    assertEquals(3, unassoc.size);
    assertEquals(3, unassoc.get(0));
    assertEquals(5, unassoc.get(1));
    assertEquals(6, unassoc.get(2));
}
Also used : TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) DogArray_I32(org.ddogleg.struct.DogArray_I32) FastArray(org.ddogleg.struct.FastArray) AssociatedIndex(boofcv.struct.feature.AssociatedIndex) Test(org.junit.jupiter.api.Test)

Example 27 with DogArray_I32

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

the class TestLlahOperations method invariantToRotation.

private void invariantToRotation(LlahOperations llahOps) {
    for (int docID = 0; docID < documents.size(); docID++) {
        llahOps.createDocument(documents.get(docID));
    }
    List<Point2D_F64> target = documents.get(2);
    List<LlahOperations.FoundDocument> foundDocuments = new ArrayList<>();
    llahOps.lookupDocuments(target, 8, foundDocuments);
    assertEquals(1, foundDocuments.size());
    DogArray_I32 expected = foundDocuments.get(0).landmarkToDots;
    for (int angleIdx = 0; angleIdx < 12; angleIdx++) {
        var se = new Se2_F64(0, 0, angleIdx * Math.PI / 4);
        // rotate and save into a new list of points
        var rotated = new ArrayList<Point2D_F64>();
        for (var p : target) {
            var d = new Point2D_F64();
            SePointOps_F64.transform(se, p, d);
            rotated.add(d);
        }
        llahOps.lookupDocuments(rotated, 8, foundDocuments);
        assertEquals(1, foundDocuments.size());
        DogArray_I32 found = foundDocuments.get(0).landmarkToDots;
        // Use the number of matches as a finger print
        for (int i = 0; i < expected.size; i++) {
            assertEquals(expected.data[i], found.data[i]);
        }
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) UtilPoint2D_F64(georegression.geometry.UtilPoint2D_F64) ArrayList(java.util.ArrayList) DogArray_I32(org.ddogleg.struct.DogArray_I32) Se2_F64(georegression.struct.se.Se2_F64)

Example 28 with DogArray_I32

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

the class TestLlahOperations method invariantToNoise.

private void invariantToNoise(LlahOperations llahOps) {
    for (int docID = 0; docID < documents.size(); docID++) {
        llahOps.createDocument(documents.get(docID));
    }
    List<Point2D_F64> target = documents.get(2);
    List<LlahOperations.FoundDocument> foundDocuments = new ArrayList<>();
    for (int trial = 0; trial < 10; trial++) {
        // add noise
        var noised = new ArrayList<Point2D_F64>();
        for (var p : target) {
            p = p.copy();
            p.x += rand.nextGaussian() * 0.03;
            p.y += rand.nextGaussian() * 0.03;
            noised.add(p);
        }
        // Look up the document
        llahOps.lookupDocuments(noised, 8, foundDocuments);
        assertEquals(1, foundDocuments.size());
        LlahOperations.FoundDocument doc = foundDocuments.get(0);
        assertEquals(2, doc.document.documentID);
        DogArray_I32 found = doc.landmarkToDots;
        // The order should be the same, but a few misses are allowed
        int totalMatched = 0;
        int totalWrong = 0;
        for (int i = 0; i < found.size; i++) {
            if (found.data[i] < 0)
                continue;
            if (i != found.data[i])
                totalWrong++;
            totalMatched++;
        }
        assertTrue(totalWrong <= 2);
        assertTrue(totalMatched >= found.size * 3 / 4);
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) UtilPoint2D_F64(georegression.geometry.UtilPoint2D_F64) ArrayList(java.util.ArrayList) DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 29 with DogArray_I32

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

the class TestImageSegmentationOps method regionPixelId_to_Compact.

private void regionPixelId_to_Compact(GrayS32 graph, GrayS32 output) {
    GrayS32 input = new GrayS32(4, 5);
    input.data = new int[] { 2, 2, 2, 5, 5, 5, 5, 5, 2, 2, 2, 2, 15, 15, 15, 15, 15, 15, 15, 15 };
    // graph might be a sub-image
    for (int y = 0; y < graph.height; y++) {
        for (int x = 0; x < graph.width; x++) {
            graph.set(x, y, adjust(input.get(x, y), graph));
        }
    }
    DogArray_I32 rootNodes = new DogArray_I32();
    rootNodes.add(adjust(2, graph));
    rootNodes.add(adjust(5, graph));
    rootNodes.add(adjust(15, graph));
    ImageSegmentationOps.regionPixelId_to_Compact(graph, rootNodes, output);
    GrayS32 expected = new GrayS32(4, 5);
    expected.data = new int[] { 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2 };
    BoofTesting.assertEquals(expected, output, 1e-4);
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32) GrayS32(boofcv.struct.image.GrayS32)

Example 30 with DogArray_I32

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

the class TestMinimizeEnergyPrune method computeSegmentEnergy.

@Test
void computeSegmentEnergy() {
    List<Point2D_I32> contours = createSquare(10, 12, 20, 30);
    DogArray_I32 corners = createSquareCorners(10, 12, 20, 30);
    // test with everything perfectly lining up
    MinimizeEnergyPrune alg = new MinimizeEnergyPrune(1);
    alg.contour = contours;
    double split = alg.splitPenalty;
    double[] expected = new double[] { split / 100.0, split / (18.0 * 18.0), split / 100.0, split / (18.0 * 18.0) };
    for (int i = 0, j = corners.size() - 1; i < corners.size(); j = i, i++) {
        double found = alg.computeSegmentEnergy(corners, j, i);
        assertEquals(expected[j], found, 1e-8);
    }
    // Now make the corners less than perfect and see if the energy increases
    corners.set(1, corners.get(1) + 1);
    corners.set(3, corners.get(3) + 1);
    for (int i = 0, j = corners.size() - 1; i < corners.size(); j = i, i++) {
        double found = alg.computeSegmentEnergy(corners, j, i);
        assertTrue(expected[j] < found);
    }
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32) DogArray_I32(org.ddogleg.struct.DogArray_I32) Test(org.junit.jupiter.api.Test)

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