Search in sources :

Example 66 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class TestRefinePolygonToGrayLine method fit_perfect_affine.

public void fit_perfect_affine(boolean black, Affine2D_F64 affine, Class imageType) {
    this.transform.set(affine);
    renderDistortedRectangles(black, imageType);
    RefinePolygonToGrayLine alg = createAlg(4, imageType);
    Polygon2D_F64 input = createFromSquare(affine);
    Polygon2D_F64 expected = input.copy();
    Polygon2D_F64 found = new Polygon2D_F64(4);
    alg.setImage(image);
    assertTrue(alg.refine(input, found));
    // input shouldn't be modified
    assertTrue(expected.isIdentical(input, 0));
    // should be close to the expected
    assertTrue(expected.isIdentical(found, 0.27));
    // do it again with a sub-image to see if it handles that
    image = BoofTesting.createSubImageOf_S(image);
    alg.setImage(image);
    assertTrue(alg.refine(input, found));
    assertTrue(expected.isIdentical(input, 0));
    assertTrue(expected.isIdentical(found, 0.27));
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 67 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class TestRefinePolygonToGrayLine method fit_tooSmall.

/**
 * Give it a shape which is too small and see if it fails
 */
@Test
public void fit_tooSmall() {
    final boolean black = true;
    Polygon2D_F64 input = new Polygon2D_F64(5, 5, 5, 6, 6, 6, 6, 5);
    rectangles.add(new Rectangle2D_I32(x0, y0, x1, y1));
    for (Class imageType : imageTypes) {
        renderDistortedRectangles(black, imageType);
        RefinePolygonToGrayLine alg = createAlg(input.size(), imageType);
        Polygon2D_F64 output = new Polygon2D_F64(input.size());
        alg.setImage(image);
        assertFalse(alg.refine(input, output));
    }
}
Also used : Rectangle2D_I32(georegression.struct.shapes.Rectangle2D_I32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 68 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class TestRefinePolygonToGrayLine method fit_subimage.

/**
 * Makes sure it can handle sub-images
 */
@Test
public void fit_subimage() {
    final boolean black = true;
    rectangles.add(new Rectangle2D_I32(x0, y0, x1, y1));
    Polygon2D_F64 input = new Polygon2D_F64(x0, y0, x0, y1, x1, y1, x1, y0);
    for (Class imageType : imageTypes) {
        renderDistortedRectangles(black, imageType);
        RefinePolygonToGrayLine alg = createAlg(input.size(), imageType);
        Polygon2D_F64 output = new Polygon2D_F64(4);
        alg.setImage(image);
        assertTrue(alg.refine(input, output));
        // do it again with a sub-image
        Polygon2D_F64 output2 = new Polygon2D_F64(4);
        image = BoofTesting.createSubImageOf_S(image);
        alg.setImage(image);
        assertTrue(alg.refine(input, output2));
        assertTrue(UtilPolygons2D_F64.isIdentical(output, output2, 1e-8));
    }
}
Also used : Rectangle2D_I32(georegression.struct.shapes.Rectangle2D_I32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 69 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class TestEdgeIntensityPolygon method computeEdge.

@Test
public void computeEdge() {
    GrayU8 image = new GrayU8(400, 500);
    int value = 200;
    ImageMiscOps.fillRectangle(image, value, 20, 30, 40, 40);
    EdgeIntensityPolygon<GrayU8> alg = new EdgeIntensityPolygon<>(2, 2, 10, GrayU8.class);
    Polygon2D_F64 polygon = new Polygon2D_F64(4);
    UtilPolygons2D_F64.convert(new Rectangle2D_F64(20, 30, 60, 70), polygon);
    alg.setImage(image);
    assertTrue(alg.computeEdge(polygon, polygon.isCCW()));
    // should be average pixel intensity inside and outside
    assertEquals(200, alg.getAverageInside(), 1e-8);
    assertEquals(0, alg.getAverageOutside(), 1e-8);
    // see what happens if the incorrect orientation is passed in
    assertTrue(alg.computeEdge(polygon, !polygon.isCCW()));
    assertEquals(0, alg.getAverageInside(), 1e-8);
    assertEquals(200, alg.getAverageOutside(), 1e-8);
}
Also used : Rectangle2D_F64(georegression.struct.shapes.Rectangle2D_F64) GrayU8(boofcv.struct.image.GrayU8) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 70 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class DetectSquareGridFiducial method extractCalibrationPoints.

/**
 * Extracts the calibration points from the corners of a fully ordered grid
 */
void extractCalibrationPoints(SquareGrid grid) {
    calibrationPoints.clear();
    for (int row = 0; row < grid.rows; row++) {
        row0.clear();
        row1.clear();
        for (int col = 0; col < grid.columns; col++) {
            Polygon2D_F64 square = grid.get(row, col).square;
            row0.add(square.get(0));
            row0.add(square.get(1));
            row1.add(square.get(3));
            row1.add(square.get(2));
        }
        calibrationPoints.addAll(row0);
        calibrationPoints.addAll(row1);
    }
// calibCols = grid.columns*2;
// calibRows = grid.rows*2;
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Aggregations

Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)79 Test (org.junit.Test)40 Point2D_F64 (georegression.struct.point.Point2D_F64)13 ArrayList (java.util.ArrayList)9 GrayU8 (boofcv.struct.image.GrayU8)6 Rectangle2D_I32 (georegression.struct.shapes.Rectangle2D_I32)6 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)5 BufferedImage (java.awt.image.BufferedImage)5 GrowQueue_B (org.ddogleg.struct.GrowQueue_B)5 Point2D_I32 (georegression.struct.point.Point2D_I32)4 PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)3 DetectPolygonFromContour (boofcv.alg.shapes.polygon.DetectPolygonFromContour)3 GrayF32 (boofcv.struct.image.GrayF32)3 Affine2D_F32 (georegression.struct.affine.Affine2D_F32)3 Se3_F64 (georegression.struct.se.Se3_F64)3 Rectangle2D_F64 (georegression.struct.shapes.Rectangle2D_F64)3 File (java.io.File)3 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)2 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)2 SquareNode (boofcv.alg.fiducial.calib.squares.SquareNode)2