use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestSnapToEllipseEdge method simpleIncorrectEstimate.
/**
* The initial estimate is slightly off
*/
@Test
public void simpleIncorrectEstimate() {
EllipseRotated_F64 target = new EllipseRotated_F64(80, 85, 50, 40, 0);
EllipseRotated_F64 input = new EllipseRotated_F64(target);
EllipseRotated_F64 found = new EllipseRotated_F64();
// make the import imprecise
input.center.x += 0.5;
input.a *= 0.97;
input.b *= 1.05;
input.phi = 0.04;
List<EllipseRotated_F64> ellipses = new ArrayList<>();
ellipses.add(target);
GrayU8 image = TestBinaryEllipseDetectorPixel.renderEllipses_F64(200, 300, ellipses, 0);
SnapToEllipseEdge<GrayU8> alg = new SnapToEllipseEdge<>(30, 1, GrayU8.class);
alg.setImage(image);
assertTrue(alg.process(input, found));
TestBinaryEllipseDetectorPixel.checkEquals(target, found, 1.0, 0.01);
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestShapeFittingOps method fitEllipse_F64_error.
/**
* Request that error be computed
*/
@Test
public void fitEllipse_F64_error() {
EllipseRotated_F64 rotated = new EllipseRotated_F64(1, 2, 3, 2, -0.05);
List<Point2D_F64> points = new ArrayList<>();
for (int i = 0; i < 20; i++) {
double theta = 2.0 * (double) Math.PI * i / 20;
points.add(UtilEllipse_F64.computePoint(theta, rotated, null));
}
points.get(5).x += 2;
// Algebraic solution
FitData<EllipseRotated_F64> found = ShapeFittingOps.fitEllipse_F64(points, 0, false, null);
assertTrue(found.error == 0);
// make sure refinement doesn't skew it up
found = ShapeFittingOps.fitEllipse_F64(points, 0, true, null);
assertTrue(found.error > 0);
// Refined solution
found = ShapeFittingOps.fitEllipse_F64(points, 10, false, null);
assertTrue(found.error == 0);
// make sure refinement doesn't skew it up
found = ShapeFittingOps.fitEllipse_F64(points, 10, true, null);
assertTrue(found.error > 0);
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class TestShapeFittingOps method fitEllipse_I32.
/**
* Checks to see if they produce the same solution
*/
@Test
public void fitEllipse_I32() {
EllipseRotated_F64 rotated = new EllipseRotated_F64(1, 2, 3, 2, -0.05);
List<Point2D_F64> pointsF = new ArrayList<>();
List<Point2D_I32> pointsI = new ArrayList<>();
for (int i = 0; i < 20; i++) {
double theta = 2.0 * (double) Math.PI * i / 20;
Point2D_F64 p = UtilEllipse_F64.computePoint(theta, rotated, null);
Point2D_I32 pi = new Point2D_I32((int) p.x, (int) p.y);
p.set(pi.x, pi.y);
pointsF.add(p);
pointsI.add(pi);
}
EllipseRotated_F64 expected = ShapeFittingOps.fitEllipse_F64(pointsF, 0, false, null).shape;
EllipseRotated_F64 found = ShapeFittingOps.fitEllipse_I32(pointsI, 0, false, null).shape;
assertEquals(expected.center.x, found.center.x, 1e-8);
assertEquals(expected.center.y, found.center.y, 1e-8);
assertEquals(expected.a, found.a, 1e-8);
assertEquals(expected.b, found.b, 1e-8);
assertEquals(expected.phi, found.phi, 1e-8);
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class EllipseClustersIntoGrid method computeNodeInfo.
/**
* For each cluster create a {@link NodeInfo} and compute different properties
*/
void computeNodeInfo(List<EllipseRotated_F64> ellipses, List<Node> cluster) {
// create an info object for each member inside of the cluster
listInfo.reset();
for (int i = 0; i < cluster.size(); i++) {
Node n = cluster.get(i);
EllipseRotated_F64 t = ellipses.get(n.which);
NodeInfo info = listInfo.grow();
info.reset();
info.ellipse = t;
}
addEdgesToInfo(cluster);
pruneNearlyIdenticalAngles();
findLargestAnglesForAllNodes();
}
use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.
the class EllipseClustersIntoGrid method addEdgesToInfo.
/**
* Adds edges to node info and computes their orientation
*/
void addEdgesToInfo(List<Node> cluster) {
for (int i = 0; i < cluster.size(); i++) {
Node n = cluster.get(i);
NodeInfo infoA = listInfo.get(i);
EllipseRotated_F64 a = infoA.ellipse;
// create the edges and order them based on their direction
for (int j = 0; j < n.connections.size(); j++) {
NodeInfo infoB = listInfo.get(indexOf(cluster, n.connections.get(j)));
EllipseRotated_F64 b = infoB.ellipse;
Edge edge = infoA.edges.grow();
edge.target = infoB;
edge.angle = Math.atan2(b.center.y - a.center.y, b.center.x - a.center.x);
}
sorter.sort(infoA.edges.data, infoA.edges.size);
}
}
Aggregations