use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class TestRefinePolyLineCorner method addPoints.
private void addPoints(int x0, int y0, int x1, int y1, List<Point2D_I32> points) {
if (x0 == x1) {
int length = Math.abs(y1 - y0);
int dir = y1 > y0 ? 1 : -1;
for (int y = 0; y < length; y++) {
points.add(new Point2D_I32(x0, y0 + dir * y));
}
} else {
int length = Math.abs(x1 - x0);
int dir = x1 > x0 ? 1 : -1;
for (int x = 0; x < length; x++) {
points.add(new Point2D_I32(x0 + dir * x, y0));
}
}
}
use of georegression.struct.point.Point2D_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 georegression.struct.point.Point2D_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));
}
use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class TestPolylineSplitMerge method computePotentialSplitScore.
@Test
public void computePotentialSplitScore() {
PolylineSplitMerge alg = new PolylineSplitMerge();
alg.setMinimumSideLength(5);
alg.setThresholdSideSplitScore(0);
List<Point2D_I32> contour = new ArrayList<>();
for (int i = 0; i < 20; i++) {
contour.add(new Point2D_I32(i, 0));
}
// add some texture
contour.get(3).y = 5;
contour.get(15).y = 5;
// this will be selected as the corner since it's the farthest away
contour.get(10).y = 20;
alg.addCorner(0);
alg.addCorner(19);
Element<Corner> e = alg.list.getHead();
e.object.sideError = 20;
alg.computePotentialSplitScore(contour, e, false);
assertTrue(e.object.splitable);
assertTrue(e.object.splitError0 > 0);
assertTrue(e.object.splitError1 > 0);
assertEquals(10, e.object.splitLocation);
}
use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class TestPolylineSplitMerge method distanceAbs.
@Test
public void distanceAbs() {
Point2D_I32 a = new Point2D_I32(2, 4);
Point2D_I32 b = new Point2D_I32(10, -3);
int expected = Math.abs(2 - 10) + Math.abs(4 + 3);
double found = PolylineSplitMerge.distanceAbs(a, b);
assertEquals(expected, found, GrlConstants.TEST_F64);
}
Aggregations