use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestRegionMergeTree method flowIntoRootNode.
@Test
void flowIntoRootNode() {
RegionMergeTree alg = new RegionMergeTree();
alg.mergeList.resize(7);
alg.mergeList.data = new int[] { 1, 1, 2, 2, 2, 3, 5 };
DogArray_I32 regionMemberCount = new DogArray_I32(7);
regionMemberCount.size = 7;
regionMemberCount.data = new int[] { 1, 2, 3, 4, 5, 6, 7 };
alg.flowIntoRootNode(regionMemberCount);
// check member count
int[] expectedCount = new int[] { 1, 3, 3 + 4 + 5 + 6 + 7, 4, 5, 6, 7 };
for (int i = 0; i < expectedCount.length; i++) assertEquals(expectedCount[i], regionMemberCount.data[i]);
// check mergeList
int[] expectedMerge = new int[] { 1, 1, 2, 2, 2, 2, 2 };
for (int i = 0; i < expectedMerge.length; i++) assertEquals(expectedMerge[i], alg.mergeList.data[i]);
// check root id
assertEquals(0, alg.rootID.get(1));
assertEquals(1, alg.rootID.get(2));
}
use of org.ddogleg.struct.DogArray_I32 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]);
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestSegmentFelzenszwalbHuttenlocher04 method computeOutput.
@Test
void computeOutput() {
SegmentFelzenszwalbHuttenlocher04 alg = new SegmentFelzenszwalbHuttenlocher04(300, 20, null);
alg.graph = new GrayS32(4, 5);
alg.graph.data = new int[] { 2, 0, 2, 5, 3, 5, 4, 6, 2, 2, 2, 1, 15, 15, 15, 15, 15, 15, 15, 15 };
for (int i = 0; i < alg.graph.data.length; i++) alg.regionSize.add(i + 1);
alg.computeOutput();
DogArray_I32 regionId = alg.getRegionId();
assertEquals(3, regionId.size);
assertEquals(2, regionId.get(0));
assertEquals(5, regionId.get(1));
assertEquals(15, regionId.get(2));
DogArray_I32 outputRegionSize = alg.getRegionSizes();
assertEquals(3, outputRegionSize.size);
assertEquals(3, outputRegionSize.get(0));
assertEquals(6, outputRegionSize.get(1));
assertEquals(16, outputRegionSize.get(2));
GrayS32 expected = new GrayS32(4, 5);
expected.data = new int[] { 2, 2, 2, 5, 5, 5, 5, 5, 2, 2, 2, 2, 15, 15, 15, 15, 15, 15, 15, 15 };
BoofTesting.assertEquals(expected, alg.graph, 1e-4);
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestFitLinesToContour method fitLine.
@Test
void fitLine() {
FitLinesToContour alg = new FitLinesToContour();
// create the rectangle so that two sizes are less than max samples and the other two more
int w = alg.maxSamples;
alg.contour = createSquare(10, 12, 10 + w - 1, 12 + w + 4);
DogArray_I32 corners = createSquareCorners(10, 12, 10 + w - 1, 12 + w + 4);
LineGeneral2D_F64 line = new LineGeneral2D_F64();
for (int i = 0, j = corners.size() - 1; i < corners.size(); j = i, i++) {
alg.fitLine(corners.get(j), corners.get(i), line);
// see if the line lies perfectly along the side
int contour0 = corners.get(j);
int contour1 = corners.get(i);
int length = CircularIndex.distanceP(contour0, contour1, alg.contour.size());
for (int k = 0; k < length; k++) {
int contourIndex = CircularIndex.addOffset(contour0, k, alg.contour.size());
Point2D_I32 p = alg.contour.get(contourIndex);
double found = Distance2D_F64.distance(line, new Point2D_F64(p.x, p.y));
assertEquals(0, found, 1e-8);
}
}
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestFitLinesToContour method sanityCheckCornerOrder.
@Test
void sanityCheckCornerOrder() {
FitLinesToContour alg = new FitLinesToContour();
alg.contour = createSquare(10, 12, 30, 40);
DogArray_I32 corners = new DogArray_I32();
corners.add(6);
corners.add(12);
corners.add(20);
corners.add(41);
corners.add(1);
// test positive cases first
for (int i = 0; i < 5; i++) {
alg.anchor0 = i;
assertTrue(alg.sanityCheckCornerOrder(3, corners));
}
// should fail
corners.add(8);
corners.add(3);
alg.anchor0 = 3;
assertFalse(alg.sanityCheckCornerOrder(4, corners));
}
Aggregations