Search in sources :

Example 56 with Polygon2D_F64

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

the class TestQrCodeDecoderImage method rotateUntilAt.

@Test
public void rotateUntilAt() {
    Polygon2D_F64 square = new Polygon2D_F64(0, 0, 2, 0, 2, 2, 0, 2);
    assertTrue(square.isCCW());
    Polygon2D_F64 original = square.copy();
    QrCodeDecoderImage.rotateUntilAt(square, 0, 0);
    assertTrue(square.isIdentical(original, UtilEjml.TEST_F64));
    QrCodeDecoderImage.rotateUntilAt(square, 1, 0);
    assertTrue(square.isCCW());
    assertTrue(square.get(0).distance(2, 0) < UtilEjml.TEST_F64);
    QrCodeDecoderImage.rotateUntilAt(square, 0, 1);
    assertTrue(square.isIdentical(original, UtilEjml.TEST_F64));
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 57 with Polygon2D_F64

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

the class FiducialTrackerDemoApp method processImage.

@Override
public void processImage(int sourceID, long frameID, BufferedImage buffered, ImageBase input) {
    detector.detect((I) input);
    Graphics2D g2 = buffered.createGraphics();
    Se3_F64 targetToSensor = new Se3_F64();
    Point2D_F64 center = new Point2D_F64();
    Polygon2D_F64 polygon = new Polygon2D_F64();
    for (int i = 0; i < detector.totalFound(); i++) {
        long id = detector.getId(i);
        if (controls.showBoundary) {
            detector.getBounds(i, polygon);
            g2.setStroke(new BasicStroke(11));
            g2.setColor(Color.BLUE);
            VisualizeShapes.drawPolygon(polygon, true, g2, true);
        }
        if (controls.showCenter) {
            detector.getCenter(i, center);
            VisualizeFeatures.drawPoint(g2, center.x, center.y, 10, Color.MAGENTA, true);
        }
        if (controls.show3D) {
            detector.getFiducialToCamera(i, targetToSensor);
            double width = detector.getWidth(i);
            VisualizeFiducial.drawLabelCenter(targetToSensor, intrinsic, "" + id, g2);
            VisualizeFiducial.drawCube(targetToSensor, intrinsic, width, 5, g2);
        }
        if (controls.showStability) {
            handleStability(input.height, g2, i, id);
        }
    }
    imageCopy = ConvertBufferedImage.checkCopy(buffered, imageCopy);
    panel.setImageUI(imageCopy);
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Se3_F64(georegression.struct.se.Se3_F64)

Example 58 with Polygon2D_F64

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

the class CommonFitPolygonChecks method renderPolygons.

public void renderPolygons(List<Polygon2D_F64> polygons, Class imageType) {
    BufferedImage work = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = work.createGraphics();
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, width, height);
    g2.setColor(Color.BLACK);
    distorted.clear();
    for (int i = 0; i < polygons.size(); i++) {
        Polygon2D_F64 orig = polygons.get(i);
        int[] x = new int[orig.size()];
        int[] y = new int[orig.size()];
        for (int j = 0; j < orig.size(); j++) {
            x[j] = (int) orig.get(j).x;
            y[j] = (int) orig.get(j).y;
        }
        g2.fillPolygon(x, y, orig.size());
        distorted.add(orig);
    }
    orig = null;
    image = GeneralizedImageOps.createSingleBand(imageType, width, height);
    ConvertBufferedImage.convertFrom(work, image, true);
    if (showRendered) {
        ListDisplayPanel panel = new ListDisplayPanel();
        panel.addImage(work, "Work");
        panel.addImage(image, "Image");
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 59 with Polygon2D_F64

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

the class CommonFitPolygonChecks method createFromSquare.

protected Polygon2D_F64 createFromSquare(Affine2D_F64 affine) {
    Polygon2D_F64 input = new Polygon2D_F64(4);
    if (affine != null) {
        AffinePointOps_F64.transform(affine, new Point2D_F64(x0, y0), input.get(0));
        AffinePointOps_F64.transform(affine, new Point2D_F64(x0, y1), input.get(1));
        AffinePointOps_F64.transform(affine, new Point2D_F64(x1, y1), input.get(2));
        AffinePointOps_F64.transform(affine, new Point2D_F64(x1, y0), input.get(3));
    } else {
        input.get(0).set(new Point2D_F64(x0, y0));
        input.get(1).set(new Point2D_F64(x0, y1));
        input.get(2).set(new Point2D_F64(x1, y1));
        input.get(3).set(new Point2D_F64(x1, y0));
    }
    return input;
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 60 with Polygon2D_F64

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

the class TestAdjustPolygonForThresholdBias method adjustForThresholdBias.

@Test
public void adjustForThresholdBias() {
    AdjustPolygonForThresholdBias alg = new AdjustPolygonForThresholdBias();
    Polygon2D_F64 original = new Polygon2D_F64(10, 10, 10, 40, 35, 40, 35, 10);
    Polygon2D_F64 shape = original.copy();
    alg.process(shape, true);
    assertTrue(shape.get(0).distance(10, 10) <= UtilEjml.EPS);
    assertTrue(shape.get(1).distance(10, 41) <= UtilEjml.EPS);
    assertTrue(shape.get(2).distance(36, 41) <= UtilEjml.EPS);
    assertTrue(shape.get(3).distance(36, 10) <= UtilEjml.EPS);
    shape = original.copy();
    shape.flip();
    alg.process(shape, false);
    assertTrue(shape.get(0).distance(10, 10) <= UtilEjml.EPS);
    assertTrue(shape.get(3).distance(10, 41) <= UtilEjml.EPS);
    assertTrue(shape.get(2).distance(36, 41) <= UtilEjml.EPS);
    assertTrue(shape.get(1).distance(36, 10) <= UtilEjml.EPS);
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

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