Search in sources :

Example 31 with DogArray_I32

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

the class TestMinimizeEnergyPrune method energyRemoveCorner.

@Test
void energyRemoveCorner() {
    List<Point2D_I32> contours = createSquare(10, 12, 20, 30);
    DogArray_I32 corners = createSquareCorners(10, 12, 20, 30);
    MinimizeEnergyPrune alg = new MinimizeEnergyPrune(1);
    alg.contour = contours;
    alg.computeSegmentEnergy(corners);
    // compute the energy with the skipped corner
    double expected = 0;
    for (int i = 0; i < 4; i++) {
        expected += alg.energySegment[i];
    }
    // add the corner which is going to be skipped
    corners.add(corners.get(3) + 4);
    alg.computeSegmentEnergy(corners);
    double found = alg.energyRemoveCorner(4, corners);
    assertEquals(expected, found, 1e-8);
    // add it in another location
    corners.removeTail();
    corners.insert(3, corners.get(2) + 3);
    alg.computeSegmentEnergy(corners);
    found = alg.energyRemoveCorner(3, corners);
    assertEquals(expected, found, 1e-8);
    // skip a different corner and the energy should go up
    corners = createSquareCorners(10, 12, 20, 30);
    for (int i = 0; i < 4; i++) {
        assertTrue(expected < alg.energyRemoveCorner(i, corners));
    }
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32) DogArray_I32(org.ddogleg.struct.DogArray_I32) Test(org.junit.jupiter.api.Test)

Example 32 with DogArray_I32

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

the class TestMinimizeEnergyPrune method prune_obvious.

/**
 * Adds an obviously redundant corner and see if it gets removed
 */
@Test
void prune_obvious() {
    List<Point2D_I32> contours = createSquare(10, 12, 20, 30);
    DogArray_I32 corners = createSquareCorners(10, 12, 20, 30);
    corners.add(corners.get(3) + 4);
    MinimizeEnergyPrune alg = new MinimizeEnergyPrune(1);
    DogArray_I32 output = new DogArray_I32();
    alg.prune(contours, corners, output);
    assertEquals(4, output.size());
    // see if the two sets of corners are equivalent, taking in account the possibility of a rotation
    checkMatched(corners, output);
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32) DogArray_I32(org.ddogleg.struct.DogArray_I32) Test(org.junit.jupiter.api.Test)

Example 33 with DogArray_I32

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

the class TestContourEdgeIntensity method computeContourVertexes.

public static DogArray_I32 computeContourVertexes(RectangleLength2D_I32 r) {
    DogArray_I32 out = new DogArray_I32();
    out.add(r.width - 2);
    out.add(r.width + r.height - 3);
    out.add(2 * r.width + r.height - 4);
    out.add(2 * r.width + 2 * r.height - 5);
    return out;
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 34 with DogArray_I32

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

the class TestSegmentMeanShiftSearchColor method simpleTest.

/**
 * Process a random image and do a basic sanity check on the output
 */
@Test
void simpleTest() {
    Planar<GrayF32> image = new Planar<>(GrayF32.class, 20, 25, 2);
    GImageMiscOps.fillUniform(image, rand, 0, 256);
    SegmentMeanShiftSearchColor<Planar<GrayF32>> alg = new SegmentMeanShiftSearchColor<>(30, 0.05f, interp, 2, 2, 200, false, imageType);
    alg.process(image);
    DogArray<Point2D_I32> locations = alg.getModeLocation();
    DogArray_I32 counts = alg.getRegionMemberCount();
    GrayS32 peaks = alg.getPixelToRegion();
    DogArray<float[]> values = alg.getModeColor();
    // there should be a fair number of local peaks due to the image being random
    assertTrue(locations.size > 20);
    // all the lists should be the same size
    assertEquals(locations.size, counts.size);
    assertEquals(locations.size, values.size);
    // total members should equal the number of pixels
    int totalMembers = 0;
    for (int i = 0; i < counts.size; i++) {
        totalMembers += counts.get(i);
    }
    assertEquals(20 * 25, totalMembers);
    // see if the peak to index image is set up correctly and that all the peaks make sense
    for (int y = 0; y < peaks.height; y++) {
        for (int x = 0; x < peaks.width; x++) {
            int peak = peaks.get(x, y);
            // can't test the value because its floating point location which is interpolated using the kernel
            // and the location is lost
            // assertEquals(x+" "+y,computeValue(peakX,peakY,image),value,50);
            assertTrue(counts.get(peak) > 0);
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) Point2D_I32(georegression.struct.point.Point2D_I32) DogArray_I32(org.ddogleg.struct.DogArray_I32) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.jupiter.api.Test)

Example 35 with DogArray_I32

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

the class TestRegionMergeTree method setToRootNodeNewID.

@Test
void setToRootNodeNewID() {
    DogArray_I32 regionMemberCount = new DogArray_I32(7);
    regionMemberCount.size = 7;
    regionMemberCount.data = new int[] { 1, 2, 3, 4, 5, 6, 7 };
    RegionMergeTree alg = new RegionMergeTree();
    alg.mergeList.resize(7);
    alg.mergeList.data = new int[] { 1, 1, 2, 2, 2, 2, 2 };
    alg.rootID.resize(7);
    alg.rootID.data = new int[] { 0, 0, 1, 0, 0, 0, 0 };
    alg.setToRootNodeNewID(regionMemberCount);
    int[] expectedCount = new int[] { 2, 3 };
    int[] expectedMerge = new int[] { 0, 0, 1, 1, 1, 1, 1 };
    assertEquals(2, regionMemberCount.size);
    for (int i = 0; i < expectedCount.length; i++) {
        assertEquals(expectedCount[i], regionMemberCount.data[i]);
    }
    for (int i = 0; i < expectedMerge.length; i++) assertEquals(expectedMerge[i], alg.mergeList.data[i]);
}
Also used : 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