use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class TestFitLinesToContour method fitLinesUsingCorners.
@Test
public void fitLinesUsingCorners() {
FitLinesToContour alg = new FitLinesToContour();
alg.contour = createSquare(10, 12, 30, 40);
GrowQueue_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.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class TestFitLinesToContour method fitLine.
@Test
public void fitLine() {
FitLinesToContour alg = new FitLinesToContour();
// create the rectangle so that two sizes are less than max samples and the other two more
int w = alg.maxSamples;
alg.contour = createSquare(10, 12, 10 + w - 1, 12 + w + 4);
GrowQueue_I32 corners = createSquareCorners(10, 12, 10 + w - 1, 12 + w + 4);
LineGeneral2D_F64 line = new LineGeneral2D_F64();
for (int i = 0, j = corners.size() - 1; i < corners.size(); j = i, i++) {
alg.fitLine(corners.get(j), corners.get(i), line);
// see if the line lies perfectly along the side
int contour0 = corners.get(j);
int contour1 = corners.get(i);
int length = CircularIndex.distanceP(contour0, contour1, alg.contour.size());
for (int k = 0; k < length; k++) {
int contourIndex = CircularIndex.addOffset(contour0, k, alg.contour.size());
Point2D_I32 p = alg.contour.get(contourIndex);
double found = Distance2D_F64.distance(line, new Point2D_F64(p.x, p.y));
assertEquals(0, found, 1e-8);
}
}
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class TestFitLinesToContour method linesIntoCorners.
@Test
public void linesIntoCorners() {
FitLinesToContour alg = new FitLinesToContour();
alg.contour = createSquare(10, 12, 30, 40);
GrowQueue_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
GrowQueue_I32 found = new GrowQueue_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.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class TestFitLinesToContour method sanityCheckCornerOrder.
@Test
public void sanityCheckCornerOrder() {
FitLinesToContour alg = new FitLinesToContour();
alg.contour = createSquare(10, 12, 30, 40);
GrowQueue_I32 corners = new GrowQueue_I32();
corners.add(6);
corners.add(12);
corners.add(20);
corners.add(41);
corners.add(1);
// test positive cases first
for (int i = 0; i < 5; i++) {
alg.anchor0 = i;
assertTrue(alg.sanityCheckCornerOrder(3, corners));
}
// should fail
corners.add(8);
corners.add(3);
alg.anchor0 = 3;
assertFalse(alg.sanityCheckCornerOrder(4, corners));
}
use of org.ddogleg.struct.GrowQueue_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));
}
}
Aggregations