Search in sources :

Example 56 with EllipseRotated_F64

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);
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) ArrayList(java.util.ArrayList) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 57 with EllipseRotated_F64

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);
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) Point2D_F64(georegression.struct.point.Point2D_F64) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 58 with EllipseRotated_F64

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);
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) Point2D_F64(georegression.struct.point.Point2D_F64) ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) Test(org.junit.Test)

Example 59 with EllipseRotated_F64

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();
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) Node(boofcv.alg.fiducial.calib.circle.EllipsesIntoClusters.Node)

Example 60 with EllipseRotated_F64

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);
    }
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) Node(boofcv.alg.fiducial.calib.circle.EllipsesIntoClusters.Node)

Aggregations

EllipseRotated_F64 (georegression.struct.curve.EllipseRotated_F64)62 ArrayList (java.util.ArrayList)34 Test (org.junit.Test)25 Grid (boofcv.alg.fiducial.calib.circle.EllipseClustersIntoGrid.Grid)18 GrayU8 (boofcv.struct.image.GrayU8)15 Point2D_F64 (georegression.struct.point.Point2D_F64)9 List (java.util.List)9 NodeInfo (boofcv.alg.fiducial.calib.circle.EllipseClustersIntoGrid.NodeInfo)5 Node (boofcv.alg.fiducial.calib.circle.EllipsesIntoClusters.Node)5 EllipsesIntoClusters (boofcv.alg.fiducial.calib.circle.EllipsesIntoClusters)2 TestDetectCircleHexagonalGrid.createGrid (boofcv.alg.fiducial.calib.circle.TestDetectCircleHexagonalGrid.createGrid)2 SquareGrid (boofcv.alg.fiducial.calib.squares.SquareGrid)2 SquareNode (boofcv.alg.fiducial.calib.squares.SquareNode)2 EllipseInfo (boofcv.alg.shapes.ellipse.BinaryEllipseDetector.EllipseInfo)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 Vector3D_F64 (georegression.struct.point.Vector3D_F64)2 AffineTransform (java.awt.geom.AffineTransform)2 BufferedImage (java.awt.image.BufferedImage)2 CalibrationDetectorCircleHexagonalGrid (boofcv.abst.fiducial.calib.CalibrationDetectorCircleHexagonalGrid)1 CalibrationDetectorCircleRegularGrid (boofcv.abst.fiducial.calib.CalibrationDetectorCircleRegularGrid)1