Search in sources :

Example 51 with EllipseRotated_F64

use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.

the class TestBinaryEllipseDetectorPixel method isApproximatelyElliptical_small.

/**
 * Test to see if it is approximately elliptical when the number of pixels is smaller
 * than the threshold
 */
@Test
public void isApproximatelyElliptical_small() {
    EllipseRotated_F64 ellipse = new EllipseRotated_F64(5, 3, 10, 6, 0);
    List<Point2D_F64> negative = TestShapeFittingOps.createRectangle_F64(20, 10, 60 - 4);
    List<Point2D_F64> positive = TestShapeFittingOps.createEllipse_F64(ellipse, 60 - 4);
    BinaryEllipseDetectorPixel alg = new BinaryEllipseDetectorPixel();
    alg.setMaxDistanceFromEllipse(1.5);
    assertFalse(alg.isApproximatelyElliptical(ellipse, negative, 100));
    assertTrue(alg.isApproximatelyElliptical(ellipse, positive, 100));
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) Point2D_F64(georegression.struct.point.Point2D_F64) Test(org.junit.Test)

Example 52 with EllipseRotated_F64

use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.

the class TestBinaryEllipseDetectorPixel method basicOnImage.

/**
 * Test the whole pipeline with a rendered image
 */
@Test
public void basicOnImage() {
    List<EllipseRotated_F64> expected = new ArrayList<>();
    expected.add(new EllipseRotated_F64(30, 38, 10, 8, 0));
    expected.add(new EllipseRotated_F64(115, 80, 20, 15, UtilEjml.F_PId2));
    GrayU8 input = renderEllipses_F64(200, 300, expected, 0);
    GrayU8 binary = input.createSameShape();
    ThresholdImageOps.threshold(input, binary, 100, true);
    // detect ovals in binary image
    BinaryEllipseDetectorPixel alg = new BinaryEllipseDetectorPixel();
    alg.process(binary);
    // compare against expected results
    List<BinaryEllipseDetectorPixel.Found> found = alg.getFound();
    List<EllipseRotated_F64> foundEllipses = new ArrayList<>();
    for (BinaryEllipseDetectorPixel.Found f : found) {
        assertTrue(f.contour.size() > 10);
        foundEllipses.add(f.ellipse);
    }
    checkEquals_F64(expected, foundEllipses, 1.0, 0.1);
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) ArrayList(java.util.ArrayList) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 53 with EllipseRotated_F64

use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.

the class TestBinaryEllipseDetectorPixel method renderEllipses_F64.

public static GrayU8 renderEllipses_F64(int width, int height, List<EllipseRotated_F64> ellipses, int color) {
    // render a binary image with two ovals
    BufferedImage buffered = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = buffered.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, width, height);
    g2.setColor(new Color(color, color, color));
    for (EllipseRotated_F64 ellipse : ellipses) {
        AffineTransform tx = new AffineTransform();
        tx.concatenate(AffineTransform.getTranslateInstance(ellipse.center.x, ellipse.center.y));
        tx.concatenate(AffineTransform.getRotateInstance(ellipse.phi));
        int a = (int) Math.round(ellipse.a);
        int b = (int) Math.round(ellipse.b);
        g2.setTransform(tx);
        g2.fillOval(-a, -b, a * 2, b * 2);
    }
    // ShowImages.showDialog(buffered);
    GrayU8 input = new GrayU8(width, height);
    ConvertBufferedImage.convertFrom(buffered, input);
    return input;
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) AffineTransform(java.awt.geom.AffineTransform) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 54 with EllipseRotated_F64

use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.

the class TestEdgeIntensityEllipse method scoreInsideAndOutside.

/**
 * Makes sure the score stays about the same when it is inside and partially outside
 */
@Test
public void scoreInsideAndOutside() {
    EllipseRotated_F64 ellipse = new EllipseRotated_F64(50, 60, 10, 5, 0.1);
    List<EllipseRotated_F64> list = new ArrayList<>();
    list.add(ellipse);
    GrayU8 image = TestBinaryEllipseDetectorPixel.renderEllipses_F64(200, 210, list, 0);
    EdgeIntensityEllipse<GrayU8> alg = new EdgeIntensityEllipse<>(1.5, 20, 10.0, GrayU8.class);
    alg.setImage(image);
    assertTrue(alg.process(ellipse));
    double score0 = alg.getEdgeIntensity();
    // Move it outside the image and render again
    ellipse.center.x = 5;
    image = TestBinaryEllipseDetectorPixel.renderEllipses_F64(200, 210, list, 0);
    alg.setImage(image);
    assertTrue(alg.process(ellipse));
    double score1 = alg.getEdgeIntensity();
    assertEquals(score0, score1, 10);
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) ArrayList(java.util.ArrayList) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 55 with EllipseRotated_F64

use of georegression.struct.curve.EllipseRotated_F64 in project BoofCV by lessthanoptimal.

the class TestSnapToEllipseEdge method computePointsAndWeights.

@Test
public void computePointsAndWeights() {
    EllipseRotated_F64 target = new EllipseRotated_F64(80, 85, 50, 40, 0);
    List<EllipseRotated_F64> ellipses = new ArrayList<>();
    ellipses.add(target);
    GrayU8 image = TestBinaryEllipseDetectorPixel.renderEllipses_F64(200, 300, ellipses, 0);
    // add a little bit of noise to prevent perfect zeros from appearing in weights
    PixelMath.plus(image, 10, 0, 255, image);
    PixelMath.multiply(image, 0.95, 0, 255, image);
    ImageMiscOps.addUniform(image, rand, -5, 5);
    int numContour = 20;
    SnapToEllipseEdge<GrayU8> alg = new SnapToEllipseEdge<>(numContour, 1, GrayU8.class);
    alg.setImage(image);
    alg.computePointsAndWeights(target);
    // all sampling was done inside the image and low change of a perfect zero
    assertEquals(3 * numContour, alg.samplePts.size);
    assertEquals(3 * numContour, alg.weights.size);
    // if the image wasn't discretized the number of zero weight would be 2 times larger than the max values
    // see if the results approximate that
    int numLow = 0, numHigh = 0;
    for (int i = 0; i < alg.weights.size(); i++) {
        if (alg.weights.data[i] < 90)
            numLow++;
        else if (alg.weights.data[i] > 120)
            numHigh++;
    }
    assertTrue(numLow > numHigh * 1.5);
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) ArrayList(java.util.ArrayList) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

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