Search in sources :

Example 26 with EllipseRotated_F64

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

the class TestKeyPointsCircleHexagonalGrid method createGrid.

public static Grid createGrid(int numRows, int numCols, double space, double radius) {
    Grid grid = new Grid();
    grid.rows = numRows;
    grid.columns = numCols;
    for (int row = 0; row < numRows; row++) {
        for (int col = 0; col < numCols; col++) {
            if (row % 2 == 0 && col % 2 == 1)
                grid.ellipses.add(null);
            else if (row % 2 == 1 && col % 2 == 0)
                grid.ellipses.add(null);
            else {
                double x = col * space;
                double y = row * space;
                grid.ellipses.add(new EllipseRotated_F64(x, y, radius, radius, 0));
            }
        }
    }
    return grid;
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) Grid(boofcv.alg.fiducial.calib.circle.EllipseClustersIntoGrid.Grid)

Example 27 with EllipseRotated_F64

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

the class TestKeyPointsCircleRegularGrid method createGrid.

public static Grid createGrid(int numRows, int numCols, double space, double radius) {
    Grid grid = new Grid();
    grid.rows = numRows;
    grid.columns = numCols;
    for (int row = 0; row < numRows; row++) {
        for (int col = 0; col < numCols; col++) {
            double x = col * space;
            double y = row * space;
            grid.ellipses.add(new EllipseRotated_F64(x, y, radius, radius, 0));
        }
    }
    return grid;
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) Grid(boofcv.alg.fiducial.calib.circle.EllipseClustersIntoGrid.Grid)

Example 28 with EllipseRotated_F64

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

the class ExampleFitEllipse method main.

public static void main(String[] args) {
    // load and convert the image into a usable format
    BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("particles01.jpg"));
    GrayF32 input = ConvertBufferedImage.convertFromSingle(image, null, GrayF32.class);
    GrayU8 binary = new GrayU8(input.width, input.height);
    // the mean pixel value is often a reasonable threshold when creating a binary image
    double mean = ImageStatistics.mean(input);
    // create a binary image by thresholding
    ThresholdImageOps.threshold(input, binary, (float) mean, true);
    // reduce noise with some filtering
    GrayU8 filtered = BinaryImageOps.erode8(binary, 1, null);
    filtered = BinaryImageOps.dilate8(filtered, 1, null);
    // Find the contour around the shapes
    List<Contour> contours = BinaryImageOps.contour(filtered, ConnectRule.EIGHT, null);
    // Fit an ellipse to each external contour and draw the results
    Graphics2D g2 = image.createGraphics();
    g2.setStroke(new BasicStroke(3));
    g2.setColor(Color.RED);
    for (Contour c : contours) {
        FitData<EllipseRotated_F64> ellipse = ShapeFittingOps.fitEllipse_I32(c.external, 0, false, null);
        VisualizeShapes.drawEllipse(ellipse.shape, g2);
    }
    // ShowImages.showWindow(VisualizeBinaryData.renderBinary(filtered, false, null),"Binary",true);
    ShowImages.showWindow(image, "Ellipses", true);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Contour(boofcv.alg.filter.binary.Contour) EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 29 with EllipseRotated_F64

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

the class TestBinaryEllipseDetector method distortedImage.

/**
 * Input image is distorted
 */
@Test
public void distortedImage() {
    List<EllipseRotated_F64> original = new ArrayList<>();
    original.add(new EllipseRotated_F64(50, 65, 20, 10, 0.5));
    original.add(new EllipseRotated_F64(90, 100, 25, 25, 0));
    GrayU8 image = TestBinaryEllipseDetectorPixel.renderEllipses_F64(200, 210, original, 0);
    GrayU8 binary = image.createSameShape();
    ThresholdImageOps.threshold(image, binary, 30, true);
    BinaryEllipseDetector<GrayU8> alg = create();
    PixelTransform2_F32 distToUndist = new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, 5, 8));
    PixelTransform2_F32 undistToDist = new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, -5, -8));
    alg.setLensDistortion(distToUndist, undistToDist);
    alg.process(image, binary);
    // adjust the ellipses using the transform
    List<EllipseRotated_F64> expected = new ArrayList<>();
    for (EllipseRotated_F64 o : original) {
        EllipseRotated_F64 e = new EllipseRotated_F64(o);
        e.center.x += 5;
        e.center.y += 8;
        expected.add(e);
    }
    List<EllipseRotated_F64> found = alg.getFoundEllipses(null);
    TestBinaryEllipseDetectorPixel.checkEquals_F64(expected, found, 1.0, 0.1);
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) Affine2D_F32(georegression.struct.affine.Affine2D_F32) ArrayList(java.util.ArrayList) GrayU8(boofcv.struct.image.GrayU8) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32) Test(org.junit.Test)

Example 30 with EllipseRotated_F64

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

the class TestBinaryEllipseDetector method autoRefineToggle.

/**
 * Turn off refinement and manually invoke it
 */
@Test
public void autoRefineToggle() {
    List<EllipseRotated_F64> expected = new ArrayList<>();
    expected.add(new EllipseRotated_F64(50, 65, 20, 10, 0.5));
    expected.add(new EllipseRotated_F64(90, 100, 25, 25, 0));
    GrayU8 image = TestBinaryEllipseDetectorPixel.renderEllipses_F64(200, 210, expected, 0);
    GrayU8 binary = image.createSameShape();
    ThresholdImageOps.threshold(image, binary, 30, true);
    BinaryEllipseDetector<GrayU8> alg = create();
    alg.setAutoRefine(false);
    alg.process(image, binary);
    List<EllipseRotated_F64> found = alg.getFoundEllipses(null);
    List<EllipseRotated_F64> refined = new ArrayList<>();
    for (EllipseRotated_F64 f : found) {
        EllipseRotated_F64 r = new EllipseRotated_F64(f);
        assertTrue(alg.refine(r));
        assertTrue(f.a != r.a);
        assertTrue(f.b != r.b);
        assertTrue(f.phi != r.phi);
        refined.add(r);
    }
    TestBinaryEllipseDetectorPixel.checkEquals_F64(refined, found, 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)

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