Search in sources :

Example 26 with Polygon2D_F64

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

the class TestDetectPolygonFromContour method determineCornersOnBorder.

@Test
public void determineCornersOnBorder() {
    DetectPolygonFromContour alg = createDetector(GrayU8.class, 4, 4);
    alg.getLabeled().reshape(width, height);
    Polygon2D_F64 poly = new Polygon2D_F64(0, 0, 10, 0, 10, 10, 0, 10);
    GrowQueue_B corners = new GrowQueue_B();
    alg.determineCornersOnBorder(poly, corners);
    assertEquals(4, corners.size());
    assertEquals(true, corners.get(0));
    assertEquals(true, corners.get(1));
    assertEquals(false, corners.get(2));
    assertEquals(true, corners.get(3));
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) GrowQueue_B(org.ddogleg.struct.GrowQueue_B) Test(org.junit.Test)

Example 27 with Polygon2D_F64

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

the class TestDetectPolygonFromContour method rejectShapes_triangle.

@Test
public void rejectShapes_triangle() {
    BufferedImage work = new BufferedImage(200, 220, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = work.createGraphics();
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, 200, 220);
    g2.setColor(Color.BLACK);
    g2.fillPolygon(new int[] { 10, 50, 30 }, new int[] { 10, 10, 40 }, 3);
    GrayU8 gray = ConvertBufferedImage.convertFrom(work, (GrayU8) null);
    binary.reshape(gray.width, gray.height);
    inputToBinary_U8.process(gray, binary);
    for (int i = 3; i <= 6; i++) {
        DetectPolygonFromContour<GrayU8> alg = createDetector(GrayU8.class, i, i);
        alg.process(gray, binary);
        if (i == 3) {
            assertEquals(1, alg.getFound().size());
            Polygon2D_F64 found = alg.getFound().get(0).polygon;
            checkPolygon(new double[] { 10, 10, 30, 40, 50, 10 }, found);
        } else
            assertEquals(0, alg.getFound().size());
    }
}
Also used : GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 28 with Polygon2D_F64

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

the class TestDetectPolygonFromContour method easyTestMultipleShapes.

@Test
public void easyTestMultipleShapes() {
    List<Polygon2D_F64> polygons = new ArrayList<>();
    polygons.add(new Polygon2D_F64(20, 20, 40, 50, 80, 20));
    polygons.add(new Polygon2D_F64(20, 60, 20, 90, 40, 90, 40, 60));
    for (Class imageType : imageTypes) {
        checkDetectedMulti(imageType, polygons, 2.5);
    }
}
Also used : ArrayList(java.util.ArrayList) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 29 with Polygon2D_F64

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

the class TestRefinePolygonToGrayLine method alignedSquare.

/**
 * Fit a square which is alligned to the image axis.  It should get a nearly perfect fit.
 * Initial conditions are be a bit off.
 */
@Test
public void alignedSquare() {
    rectangles.add(new Rectangle2D_I32(x0, y0, x1, y1));
    Polygon2D_F64 original = new Polygon2D_F64(x0, y0, x0, y1, x1, y1, x1, y0);
    for (Class imageType : imageTypes) {
        for (int i = 0; i < 2; i++) {
            boolean black = i == 0;
            renderDistortedRectangles(black, imageType);
            RefinePolygonToGrayLine alg = createAlg(original.size(), imageType);
            for (int j = 0; j < 20; j++) {
                Polygon2D_F64 input = original.copy();
                addNoise(input, 2);
                Polygon2D_F64 output = new Polygon2D_F64(original.size());
                alg.setImage(image);
                assertTrue(alg.refine(input, output));
                assertTrue(original.isIdentical(output, 0.01));
            }
        }
    }
}
Also used : Rectangle2D_I32(georegression.struct.shapes.Rectangle2D_I32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 30 with Polygon2D_F64

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

the class TestRefinePolygonToGrayLine method fit_noisy_affine.

public void fit_noisy_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);
    for (int i = 0; i < 10; i++) {
        // add some noise
        input.set(expected);
        addNoise(input, 2);
        alg.setImage(image);
        assertTrue(alg.refine(input, found));
        // should be close to the expected
        double before = computeMaxDistance(input, expected);
        double after = computeMaxDistance(found, expected);
        assertTrue(after < before);
        assertTrue(expected.isIdentical(found, 0.5));
        // ----- Reverse the order and it should still work
        input.flip();
        assertTrue(alg.refine(input, found));
        found.flip();
        after = computeMaxDistance(found, expected);
        assertTrue(after < before);
        assertTrue(expected.isIdentical(found, 0.5));
    }
}
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