use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class TestPolylineSplitMerge method line.
public static List<Point2D_I32> line(int x0, int y0, int x1, int y1) {
List<Point2D_I32> out = new ArrayList<>();
int lengthY = Math.abs(y1 - y0);
int lengthX = Math.abs(x1 - x0);
int x, y;
if (lengthY > lengthX) {
for (int i = 0; i < lengthY; i++) {
x = x0 + (x1 - x0) * lengthX * i / lengthY;
y = y0 + (y1 - y0) * i / lengthY;
out.add(new Point2D_I32(x, y));
}
} else {
for (int i = 0; i < lengthX; i++) {
x = x0 + (x1 - x0) * i / lengthX;
y = y0 + (y1 - y0) * lengthY * i / lengthX;
out.add(new Point2D_I32(x, y));
}
}
return out;
}
use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class TestPolylineSplitMerge method assignLine_segment.
@Test
public void assignLine_segment() {
List<Point2D_I32> contour = new ArrayList<>();
for (int i = 0; i < 20; i++) {
contour.add(new Point2D_I32(i, 2));
}
// make these points offset from all the others. That way if it grabs the wrong points the line will be wrong
contour.get(1).set(1, 5);
contour.get(9).set(9, 5);
LineSegment2D_F64 line = new LineSegment2D_F64();
PolylineSplitMerge.assignLine(contour, 1, 9, line);
assertEquals(1, Distance2D_F64.distanceSq(line, 0, 5), GrlConstants.TEST_F64);
assertEquals(0, Distance2D_F64.distanceSq(line, 2, 5), GrlConstants.TEST_F64);
assertEquals(0, Distance2D_F64.distanceSq(line, 8, 5), GrlConstants.TEST_F64);
}
use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class TestPolylineSplitMerge method canBeSplit.
@Test
public void canBeSplit() {
PolylineSplitMerge alg = new PolylineSplitMerge();
// only the contour's size matters
List<Point2D_I32> contour = new ArrayList<>();
for (int i = 0; i < 50; i++) {
contour.add(new Point2D_I32());
}
for (int i = 0; i < 10; i++) {
Corner c = alg.corners.grow();
c.index = i * 5;
// give it an error greater than zero so that it will pass the side test
c.sideError = 0.1;
alg.list.pushTail(c);
}
alg.setMinimumSideLength(4);
// turn off this test
alg.setThresholdSideSplitScore(0);
assertTrue(alg.canBeSplit(contour, alg.list.getElement(5, true), false));
assertTrue(alg.canBeSplit(contour, alg.list.getElement(9, true), false));
alg.setMinimumSideLength(5);
assertFalse(alg.canBeSplit(contour, alg.list.getElement(5, true), false));
assertFalse(alg.canBeSplit(contour, alg.list.getElement(9, true), false));
// test side split score
alg.setMinimumSideLength(4);
alg.setThresholdSideSplitScore(1);
alg.list.getElement(5, true).object.sideError = 1.0000001;
assertTrue(alg.canBeSplit(contour, alg.list.getElement(5, true), false));
alg.list.getElement(5, true).object.sideError = 0.9999999;
assertFalse(alg.canBeSplit(contour, alg.list.getElement(5, true), false));
// test the must split flag
alg.list.getElement(5, true).object.sideError = 0.9999999;
assertTrue(alg.canBeSplit(contour, alg.list.getElement(5, true), true));
alg.setMinimumSideLength(6);
assertFalse(alg.canBeSplit(contour, alg.list.getElement(5, true), true));
// Will it try to split a side with zero error if the min score is zero?
alg.setMinimumSideLength(4);
alg.setThresholdSideSplitScore(0);
alg.corners.get(0).sideError = 0;
assertFalse(alg.canBeSplit(contour, alg.list.getHead(), false));
// now the minimum length is 1 and the side isn't perfect. Still shouldn't split
// because the length is now 1
alg.setMinimumSideLength(1);
alg.corners.get(0).sideError = 0.1;
alg.corners.get(0).index = 0;
alg.corners.get(1).index = 1;
assertFalse(alg.canBeSplit(contour, alg.list.getHead(), false));
}
use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class TestPolylineSplitMerge method distanceSq.
@Test
public void distanceSq() {
Point2D_I32 a = new Point2D_I32(2, 4);
Point2D_I32 b = new Point2D_I32(10, -3);
int expected = a.distance2(b);
double found = PolylineSplitMerge.distanceSq(a, b);
assertEquals(expected, found, GrlConstants.TEST_F64);
}
use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.
the class TestPolylineSplitMerge method computeSideError_exhaustive.
@Test
public void computeSideError_exhaustive() {
PolylineSplitMerge alg = new PolylineSplitMerge();
// have it exhaustively sample all pixels
alg.maxNumberOfSideSamples = 300;
List<Point2D_I32> contour = new ArrayList<>();
for (int i = 0; i < 20; i++) {
contour.add(new Point2D_I32(i, 0));
}
assertEquals(0, alg.computeSideError(contour, 0, 19), GrlConstants.TEST_F64);
for (int i = 1; i < 19; i++) {
contour.get(i).y = 5;
}
// need this to be zero so that two lines are the same
contour.get(10).y = 0;
// // average SSE
double expected = (5.0 * 5.0 * 17) / 18.0;
assertEquals(expected, alg.computeSideError(contour, 0, 19), GrlConstants.TEST_F64);
// the error should have this property to not bias it based on the number of sides
expected = (5 * 5 * 9) / 9.0 + (5 * 5 * 8) / 8.0;
double split = alg.computeSideError(contour, 0, 10) + alg.computeSideError(contour, 10, 19);
assertEquals(expected, split, GrlConstants.TEST_F64);
// ----------- Test the wrapping around case
List<Point2D_I32> contour2 = new ArrayList<>();
for (int i = 0; i < contour.size(); i++) {
contour2.add(contour.get((i + 10) % contour.size()));
}
expected = (5 * 5 * 9) / 9.0;
assertEquals(expected, alg.computeSideError(contour2, 10, 0), GrlConstants.TEST_F64);
}
Aggregations