use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class TestMinimizeEnergyPrune method computeSegmentEnergy.
@Test
public void computeSegmentEnergy() {
List<Point2D_I32> contours = createSquare(10, 12, 20, 30);
GrowQueue_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);
}
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class TestMinimizeEnergyPrune method prune_obvious.
/**
* Adds an obviously redundant corner and see if it gets removed
*/
@Test
public void prune_obvious() {
List<Point2D_I32> contours = createSquare(10, 12, 20, 30);
GrowQueue_I32 corners = createSquareCorners(10, 12, 20, 30);
corners.add(corners.get(3) + 4);
MinimizeEnergyPrune alg = new MinimizeEnergyPrune(1);
GrowQueue_I32 output = new GrowQueue_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);
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class TestRefinePolyLineCorner method fit_six_sides.
/**
* Fit six sided shape
*/
@Test
public void fit_six_sides() {
List<Point2D_I32> points = new ArrayList<>();
addPoints(0, 0, 20, 0, points);
addPoints(20, 0, 20, 20, points);
addPoints(20, 20, 40, 20, points);
addPoints(40, 20, 40, 40, points);
addPoints(40, 40, 0, 40, points);
addPoints(0, 40, 0, 0, points);
GrowQueue_I32 corners = new GrowQueue_I32();
corners.add(0);
corners.add(20);
corners.add(40);
corners.add(60);
corners.add(80);
corners.add(120);
RefinePolyLineCorner alg = new RefinePolyLineCorner(true);
for (int i = 0; i < 10; i++) {
// noise up the inputs
for (int j = 0; j < corners.size(); j++) {
corners.data[j] = CircularIndex.addOffset(corners.data[j], rand.nextInt(10) - 5, points.size());
}
assertTrue(alg.fit(points, corners));
assertEquals(0, corners.get(0));
assertEquals(20, corners.get(1));
assertEquals(40, corners.get(2));
assertEquals(60, corners.get(3));
assertEquals(80, corners.get(4));
assertEquals(120, corners.get(5));
}
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class TestRefinePolyLineCorner method fit_quad_segment.
/**
* Fit to a square, but only a disconnected polyline on 3 sides
*/
@Test
public void fit_quad_segment() {
int x0 = 10, y0 = 15;
int x1 = 60, y1 = 99;
List<Point2D_I32> points = new ArrayList<>();
addPoints(x0, y0, x1, y0, points);
addPoints(x1, y0, x1, y1, points);
addPoints(x1, y1, x0, y1, points);
RefinePolyLineCorner alg = new RefinePolyLineCorner(false);
for (int i = 0; i < 10; i++) {
GrowQueue_I32 corners = new GrowQueue_I32();
corners.add(0);
corners.add(50 + rand.nextInt(6) - 3);
corners.add(50 + 84 + rand.nextInt(6) - 3);
corners.add(points.size() - 1);
assertTrue(alg.fit(points, corners));
assertEquals(0, corners.get(0));
assertEquals(50, corners.get(1));
assertEquals(134, corners.get(2));
assertEquals(points.size() - 1, corners.get(3));
}
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class TestRefinePolyLineCorner method fit_quad.
/**
* Fit to a square
*/
@Test
public void fit_quad() {
int x0 = 10, y0 = 15;
int x1 = 60, y1 = 99;
List<Point2D_I32> points = new ArrayList<>();
addPoints(x0, y0, x1, y0, points);
addPoints(x1, y0, x1, y1, points);
addPoints(x1, y1, x0, y1, points);
addPoints(x0, y1, x0, y0, points);
RefinePolyLineCorner alg = new RefinePolyLineCorner(true);
GrowQueue_I32 corners = new GrowQueue_I32();
corners.add(0);
corners.add(50);
corners.add(50 + 84);
corners.add(50 + 84 + 50);
assertTrue(alg.fit(points, corners));
assertEquals(0, corners.get(0));
assertEquals(50, corners.get(1));
assertEquals(134, corners.get(2));
assertEquals(184, corners.get(3));
}
Aggregations