use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestFitLinesToContour method linesIntoCorners.
@Test
void linesIntoCorners() {
FitLinesToContour alg = new FitLinesToContour();
alg.contour = createSquare(10, 12, 30, 40);
DogArray_I32 corners = createSquareCorners(10, 12, 30, 40);
// first generate the lines it will fit
alg.lines.resize(3);
alg.anchor0 = 1;
alg.fitLinesUsingCorners(3, corners);
// now extract the corners
DogArray_I32 found = new DogArray_I32(corners.size);
found.resize(corners.size());
alg.anchor0 = 1;
alg.linesIntoCorners(3, found);
// only corners 2 and 3 should be updated with no change
for (int i = 2; i < found.size(); i++) {
assertEquals(corners.get(i), found.get(i));
}
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestFitLinesToContour method fitLinesUsingCorners.
@Test
void fitLinesUsingCorners() {
FitLinesToContour alg = new FitLinesToContour();
alg.contour = createSquare(10, 12, 30, 40);
DogArray_I32 corners = createSquareCorners(10, 12, 30, 40);
alg.lines.resize(3);
alg.anchor0 = 1;
alg.fitLinesUsingCorners(3, corners);
LineGeneral2D_F64 expected = new LineGeneral2D_F64();
for (int i = 0; i < 3; i++) {
alg.fitLine(corners.get((i + 1) % 4), corners.get((i + 2) % 4), expected);
LineGeneral2D_F64 found = alg.lines.get(i);
assertEquals(expected.A, found.A, 1e-8);
assertEquals(expected.B, found.B, 1e-8);
assertEquals(expected.C, found.C, 1e-8);
}
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestRefinePolyLineCorner method fit_six_sides.
/**
* Fit six sided shape
*/
@Test
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);
DogArray_I32 corners = new DogArray_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.DogArray_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
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++) {
DogArray_I32 corners = new DogArray_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.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestRefinePolyLineCorner method fit_quad.
/**
* Fit to a square
*/
@Test
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);
DogArray_I32 corners = new DogArray_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