use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class KeyPointsCircleRegularGrid method addTangents.
/**
* Computes tangent points to the two ellipses specified by the grid coordinates
*/
private boolean addTangents(Grid grid, int rowA, int colA, int rowB, int colB) {
EllipseRotated_F64 a = grid.get(rowA, colA);
EllipseRotated_F64 b = grid.get(rowB, colB);
if (!tangentFinder.process(a, b, A0, A1, A2, A3, B0, B1, B2, B3)) {
return false;
}
Tangents ta = tangents.get(grid.getIndexOfRegEllipse(rowA, colA));
Tangents tb = tangents.get(grid.getIndexOfRegEllipse(rowB, colB));
// Which point is 0 or 3 is not defined and can swap arbitrarily. To fix this problem
// 0 will be defined as on the 'positive side' of the line connecting the ellipse centers
double slopeX = b.center.x - a.center.x;
double slopeY = b.center.y - a.center.y;
double dx0 = A0.x - a.center.x;
double dy0 = A0.y - a.center.y;
double z = slopeX * dy0 - slopeY * dx0;
if (z < 0 == (rowA == rowB)) {
Point2D_F64 tmp = A0;
A0 = A3;
A3 = tmp;
tmp = B0;
B0 = B3;
B3 = tmp;
}
// add tangent points from the two lines which do not cross the center line
if (rowA == rowB) {
ta.t[ta.countT++].set(A0);
ta.b[ta.countB++].set(A3);
tb.t[tb.countT++].set(B0);
tb.b[tb.countB++].set(B3);
} else {
ta.r[ta.countL++].set(A0);
ta.l[ta.countR++].set(A3);
tb.r[tb.countL++].set(B0);
tb.l[tb.countR++].set(B3);
}
return true;
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestDetectCircleGrid method rotateGridCCW.
@Test
public void rotateGridCCW() {
Grid g = createGrid(3, 3);
List<EllipseRotated_F64> original = new ArrayList<>();
original.addAll(g.ellipses);
DetectCircleGrid<?> alg = new HelperAlg(3, 3);
alg.rotateGridCCW(g);
assertEquals(9, g.ellipses.size());
assertTrue(original.get(6) == g.get(0, 0));
assertTrue(original.get(0) == g.get(0, 2));
assertTrue(original.get(2) == g.get(2, 2));
assertTrue(original.get(8) == g.get(2, 0));
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestDetectCircleHexagonalGrid method performDetectionCheck.
private void performDetectionCheck(int expectedRows, int expectedCols, int actualRows, int actualCols, Affine2D_F64 affine) {
int radius = 20;
int centerDistances = 50;
DetectCircleHexagonalGrid<GrayU8> alg = createAlg(expectedRows, expectedCols, radius, centerDistances);
// alg.setVerbose(true);
List<Point2D_F64> locations = new ArrayList<>();
GrayU8 image = new GrayU8(400, 450);
render(actualRows, actualCols, radius, centerDistances, affine, locations, image);
alg.process(image);
List<Grid> found = alg.getGrids();
if (expectedRows != actualRows || expectedCols != actualCols) {
assertEquals(0, found.size());
return;
} else {
assertEquals(1, found.size());
}
Grid g = found.get(0);
assertEquals(actualRows, g.rows);
assertEquals(actualCols, g.columns);
TestDetectCircleHexagonalGrid.checkCounterClockWise(g);
int index = 0;
for (int row = 0; row < g.rows; row++) {
for (int col = 0; col < g.columns; col++) {
boolean check = false;
if (row % 2 == 1 && col % 2 == 1)
check = true;
else if (row % 2 == 0 && col % 2 == 0)
check = true;
if (check) {
EllipseRotated_F64 f = g.get(row, col);
Point2D_F64 e = locations.get(index++);
assertEquals(e.x, f.center.x, 1.5);
assertEquals(e.y, f.center.y, 1.5);
assertEquals(20, f.a, 1.0);
assertEquals(20, f.b, 1.0);
}
}
}
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestDetectCircleHexagonalGrid method putGridIntoCanonical_rotate.
public void putGridIntoCanonical_rotate(int numRows, int numCols) {
DetectCircleHexagonalGrid<?> alg = new DetectCircleHexagonalGrid(numRows, numCols, null, null, null);
Grid g = createGrid(numRows, numCols);
List<EllipseRotated_F64> original = new ArrayList<>();
original.addAll(g.ellipses);
alg.putGridIntoCanonical(g);
assertEquals(numRows, g.rows);
assertEquals(numCols, g.columns);
assertTrue(original.get(0) == g.get(0, 0));
checkCounterClockWise(g);
alg.rotateGridCCW(g);
alg.putGridIntoCanonical(g);
assertTrue(original.get(0) == g.get(0, 0));
checkCounterClockWise(g);
alg.rotateGridCCW(g);
alg.rotateGridCCW(g);
alg.putGridIntoCanonical(g);
assertTrue(original.get(0) == g.get(0, 0));
checkCounterClockWise(g);
alg.rotateGridCCW(g);
alg.rotateGridCCW(g);
alg.rotateGridCCW(g);
alg.putGridIntoCanonical(g);
assertTrue(original.get(0) == g.get(0, 0));
checkCounterClockWise(g);
alg.flipVertical(g);
alg.putGridIntoCanonical(g);
assertTrue(original.get(0) == g.get(0, 0));
checkCounterClockWise(g);
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestDetectCircleHexagonalGrid method putGridIntoCanonical_horizontal.
private void putGridIntoCanonical_horizontal(int numRows, int numCols) {
DetectCircleHexagonalGrid<?> alg = new DetectCircleHexagonalGrid(numRows, numCols, null, null, null);
Grid g = createGrid(numRows, numCols);
List<EllipseRotated_F64> original = new ArrayList<>();
original.addAll(g.ellipses);
alg.putGridIntoCanonical(g);
assertEquals(numRows, g.rows);
assertEquals(numCols, g.columns);
assertTrue(original.get(0) == g.get(0, 0));
checkCounterClockWise(g);
g = TestDetectCircleGrid.flipHorizontal(g);
alg.putGridIntoCanonical(g);
assertEquals(numRows, g.rows);
assertEquals(numCols, g.columns);
assertTrue(original.get(0) == g.get(0, 0));
checkCounterClockWise(g);
}
Aggregations