Search in sources :

Example 36 with Polygon2D_F64

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

the class CommonFitPolygonChecks method renderDistortedRectangles.

public void renderDistortedRectangles(boolean blackShape, Class imageType) {
    orig = GeneralizedImageOps.createSingleBand(imageType, width, height);
    image = GeneralizedImageOps.createSingleBand(imageType, width, height);
    int white = blackShape ? this.white : this.black;
    int black = blackShape ? this.black : this.white;
    GImageMiscOps.fill(orig, white);
    GImageMiscOps.fill(image, white);
    distorted.clear();
    for (Rectangle2D_I32 q : rectangles) {
        if (fittingToBinaryImage)
            GImageMiscOps.fillRectangle(orig, black, q.x0, q.y0, q.x1 - q.x0 + 1, q.y1 - q.y0 + 1);
        else
            GImageMiscOps.fillRectangle(orig, black, q.x0, q.y0, q.x1 - q.x0, q.y1 - q.y0);
        Polygon2D_F64 tran = new Polygon2D_F64(4);
        AffinePointOps_F64.transform(transform, q.x0, q.y0, tran.get(0));
        AffinePointOps_F64.transform(transform, q.x0, q.y1, tran.get(1));
        AffinePointOps_F64.transform(transform, q.x1, q.y1, tran.get(2));
        AffinePointOps_F64.transform(transform, q.x1, q.y0, tran.get(3));
        distorted.add(tran);
    }
    new FDistort(orig, image).border(white).affine(transform).apply();
    if (showRendered) {
        ListDisplayPanel panel = new ListDisplayPanel();
        panel.addImage(orig, "Original");
        panel.addImage(image, "Image");
        ShowImages.showWindow(panel, "Rendered");
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) FDistort(boofcv.abst.distort.FDistort) Rectangle2D_I32(georegression.struct.shapes.Rectangle2D_I32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 37 with Polygon2D_F64

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

the class TestDetectPolygonBinaryGrayRefine method checkDetected_LensDistortion.

private void checkDetected_LensDistortion(Class imageType, double tol) {
    renderDistortedRectangles(true, imageType);
    Affine2D_F32 a = new Affine2D_F32();
    UtilAffine.convert(transform, a);
    PixelTransform2_F32 tranFrom = new PixelTransformAffine_F32(a);
    PixelTransform2_F32 tranTo = new PixelTransformAffine_F32(a.invert(null));
    int numberOfSides = 4;
    DetectPolygonBinaryGrayRefine alg = createAlg(imageType, numberOfSides, numberOfSides);
    alg.setLensDistortion(image.width, image.height, tranTo, tranFrom);
    alg.process(image, binary);
    List<DetectPolygonFromContour.Info> found = alg.getPolygonInfo();
    assertEquals(rectangles.size(), found.size());
    for (int i = 0; i < found.size(); i++) {
        Polygon2D_F64 p = found.get(i).polygon;
        assertEquals(1, findMatchesOriginal(p, tol));
        assertEquals(black, found.get(i).edgeInside, 3);
        assertEquals(white, found.get(i).edgeOutside, white * 0.05);
    }
    // ----------- see if distortion is cleared properly
    alg.clearLensDistortion();
    alg.process(image, binary);
    found = alg.getPolygonInfo();
    assertEquals(rectangles.size(), found.size());
    // nothing should match now
    for (int i = 0; i < found.size(); i++) {
        Polygon2D_F64 p = found.get(i).polygon;
        assertEquals(0, findMatchesOriginal(p, tol));
    }
}
Also used : Affine2D_F32(georegression.struct.affine.Affine2D_F32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32)

Example 38 with Polygon2D_F64

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

the class TestDetectPolygonBinaryGrayRefine method checkSolutions.

private void checkSolutions(double tolerance, List<DetectPolygonFromContour.Info> found) {
    for (int i = 0; i < found.size(); i++) {
        Polygon2D_F64 p = found.get(i).polygon;
        assertEquals(1, findMatches(p, tolerance));
        assertEquals(black, found.get(i).edgeInside, 4);
        assertEquals(white, found.get(i).edgeOutside, white * 0.1);
    }
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 39 with Polygon2D_F64

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

the class TestEdgeIntensityPolygon method checkIntensity.

@Test
public void checkIntensity() {
    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()));
    assertTrue(alg.checkIntensity(false, 50));
    assertFalse(alg.checkIntensity(true, 50));
}
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 40 with Polygon2D_F64

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

the class AssistedCalibration method renderFillPolygons.

private void renderFillPolygons() {
    if (regions.size() == 0)
        return;
    g2.setColor(new Color(0, 255, 255, 50));
    int N = regions.get(0).size();
    int[] polyX = new int[N];
    int[] polyY = new int[N];
    for (int i = 0; i < regions.size(); i++) {
        Polygon2D_F64 poly = regions.get(i);
        for (int j = 0; j < poly.size(); j++) {
            Point2D_F64 p = poly.get(j);
            polyX[j] = (int) (p.x + 0.5);
            polyY[j] = (int) (p.y + 0.5);
        }
        g2.fillPolygon(polyX, polyY, poly.size());
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) UtilPoint2D_F64(georegression.geometry.UtilPoint2D_F64) 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