use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class TestFitLinesToContour method closestPoint.
@Test
public void closestPoint() {
FitLinesToContour alg = new FitLinesToContour();
alg.contour = createSquare(10, 12, 30, 40);
Point2D_F64 p = new Point2D_F64(15.5, 11);
Point2D_I32 corner = alg.contour.get(alg.closestPoint(p));
assertEquals(15, corner.x);
assertEquals(12, corner.y);
}
use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class TestMinimizeEnergyPrune method energyRemoveCorner.
@Test
public void energyRemoveCorner() {
List<Point2D_I32> contours = createSquare(10, 12, 20, 30);
GrowQueue_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));
}
}
use of georegression.struct.point.Point2D_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 georegression.struct.point.Point2D_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 georegression.struct.point.Point2D_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));
}
}
Aggregations