Search in sources :

Example 11 with Quadrilateral_F64

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

the class VisualizeSquareFiducial method process.

public void process(String nameImage, @Nullable String nameIntrinsic) {
    CameraPinholeBrown intrinsic = nameIntrinsic == null ? null : (CameraPinholeBrown) CalibrationIO.load(nameIntrinsic);
    GrayF32 input = Objects.requireNonNull(UtilImageIO.loadImage(nameImage, GrayF32.class));
    GrayF32 undistorted = new GrayF32(input.width, input.height);
    Detector detector = new Detector();
    if (intrinsic != null) {
        var paramUndist = new CameraPinholeBrown();
        ImageDistort<GrayF32, GrayF32> undistorter = LensDistortionOps.changeCameraModel(AdjustmentType.EXPAND, BorderType.EXTENDED, intrinsic, new CameraPinhole(intrinsic), paramUndist, ImageType.single(GrayF32.class));
        detector.configure(new LensDistortionBrown(paramUndist), paramUndist.width, paramUndist.height, false);
        undistorter.apply(input, undistorted);
    } else {
        undistorted.setTo(input);
    }
    detector.process(undistorted);
    System.out.println("Total Found: " + detector.squares.size());
    DogArray<FoundFiducial> fiducials = detector.getFound();
    int N = Math.min(20, detector.squares.size());
    ListDisplayPanel squares = new ListDisplayPanel();
    for (int i = 0; i < N; i++) {
        squares.addImage(ConvertBufferedImage.convertTo(detector.squares.get(i), null), " " + i);
    }
    BufferedImage output = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
    VisualizeBinaryData.renderBinary(detector.getBinary(), false, output);
    Graphics2D g2 = output.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.RED);
    g2.setStroke(new BasicStroke(2));
    if (intrinsic != null) {
        Point2Transform2_F64 add_p_to_p = LensDistortionFactory.narrow(intrinsic).distort_F64(true, true);
        for (int i = 0; i < N; i++) {
            // add back in lens distortion
            Quadrilateral_F64 q = fiducials.get(i).distortedPixels;
            apply(add_p_to_p, q.a, q.a);
            apply(add_p_to_p, q.b, q.b);
            apply(add_p_to_p, q.c, q.c);
            apply(add_p_to_p, q.d, q.d);
            VisualizeShapes.draw(q, g2);
        }
    }
    BufferedImage outputGray = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
    ConvertBufferedImage.convertTo(undistorted, outputGray);
    g2 = outputGray.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    for (int i = 0; i < N; i++) {
        // add back in lens distortion
        Quadrilateral_F64 q = fiducials.get(i).distortedPixels;
        // g2.setStroke(new BasicStroke(2));
        // VisualizeBinaryData.render(detector.getSquareDetector().getUsedContours(),Color.BLUE,outputGray);
        VisualizeShapes.drawArrowSubPixel(q, 3, 1, g2);
    }
    ShowImages.showWindow(output, "Binary");
    ShowImages.showWindow(outputGray, "Gray");
    ShowImages.showWindow(squares, "Candidates");
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) LensDistortionBrown(boofcv.alg.distort.brown.LensDistortionBrown) Quadrilateral_F64(georegression.struct.shapes.Quadrilateral_F64) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) FoundFiducial(boofcv.alg.fiducial.square.FoundFiducial) CameraPinhole(boofcv.struct.calib.CameraPinhole) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) GrayF32(boofcv.struct.image.GrayF32) FactoryShapeDetector(boofcv.factory.shape.FactoryShapeDetector) ConfigPolygonDetector(boofcv.factory.shape.ConfigPolygonDetector)

Example 12 with Quadrilateral_F64

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

the class TestStitchingFromMotion2D method getImageCorners.

@Test
void getImageCorners() {
    HelperMotion motion = new HelperMotion();
    HelperDistort distort = new HelperDistort();
    StitchingTransform trans = FactoryStitchingTransform.createAffine_F64();
    StitchingFromMotion2D<GrayF32, Affine2D_F64> alg = new StitchingFromMotion2D<>(motion, distort, trans, 0.3);
    alg.configure(200, 300, null);
    assertTrue(alg.process(image));
    int w = 100, h = 150;
    Quadrilateral_F64 corners = new Quadrilateral_F64();
    alg.getImageCorners(w, h, corners);
    assertEquals(-1, corners.a.x, 1e-5);
    assertEquals(2, corners.a.y, 1e-5);
    assertEquals(-1 + w, corners.b.x, 1e-5);
    assertEquals(2, corners.b.y, 1e-5);
    assertEquals(-1 + w, corners.c.x, 1e-5);
    assertEquals(2 + h, corners.c.y, 1e-5);
    assertEquals(-1, corners.d.x, 1e-5);
    assertEquals(2 + h, corners.d.y, 1e-5);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Affine2D_F64(georegression.struct.affine.Affine2D_F64) Quadrilateral_F64(georegression.struct.shapes.Quadrilateral_F64) Test(org.junit.jupiter.api.Test)

Example 13 with Quadrilateral_F64

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

the class Motion2DPanel method drawImageBounds.

private void drawImageBounds(Graphics2D g2, int tx, int ty, double scale) {
    Quadrilateral_F64 c = corners;
    Stroke originalStroke = g2.getStroke();
    g2.setStroke(boundsStroke);
    g2.setColor(Color.BLUE);
    drawLine(g2, tx, ty, scale, c.a, c.b);
    drawLine(g2, tx, ty, scale, c.b, c.c);
    drawLine(g2, tx, ty, scale, c.c, c.d);
    drawLine(g2, tx, ty, scale, c.d, c.a);
    g2.setStroke(originalStroke);
}
Also used : Quadrilateral_F64(georegression.struct.shapes.Quadrilateral_F64)

Example 14 with Quadrilateral_F64

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

the class TestDetectFiducialSquareGrid method simple.

/**
 * Generate a fiducial and detect its corners. Fully visible.
 */
@Test
void simple() {
    ConfigFiducialBinary configBinary = new ConfigFiducialBinary(1);
    configBinary.gridWidth = 3;
    long[] values = new long[] { 0, 1, 2, 3, 4, 5 };
    BaseDetectFiducialSquare<GrayF32> detector = FactoryFiducial.squareBinary(configBinary, ConfigThreshold.fixed(125), GrayF32.class).getAlgorithm();
    DetectFiducialSquareGrid<GrayF32> alg = new DetectFiducialSquareGrid<>(3, 2, values, detector);
    RenderSquareBinaryGridFiducial render = new RenderSquareBinaryGridFiducial();
    render.values = values;
    GrayF32 image = render.generate(3, 2);
    assertTrue(alg.detect(image));
    List<DetectFiducialSquareGrid.Detection> detections = alg.detections.toList();
    int[] foundIds = new int[6];
    for (int i = 0; i < detections.size(); i++) {
        DetectFiducialSquareGrid.Detection d = detections.get(i);
        foundIds[d.gridIndex]++;
        // see if the corners are in the right location. Order matters
        Quadrilateral_F64 expected = render.expectedCorners.get(d.gridIndex);
        Quadrilateral_F64 found = d.location;
        for (int j = 0; j < 4; j++) {
            assertTrue(expected.get(j).distance(found.get(j)) < 0.1);
        }
    }
    // see if all the fiducials were found
    for (int i = 0; i < foundIds.length; i++) {
        assertEquals(1, foundIds[i]);
    }
}
Also used : ConfigFiducialBinary(boofcv.factory.fiducial.ConfigFiducialBinary) Quadrilateral_F64(georegression.struct.shapes.Quadrilateral_F64) GrayF32(boofcv.struct.image.GrayF32) Test(org.junit.jupiter.api.Test)

Example 15 with Quadrilateral_F64

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

the class RenderSquareBinaryGridFiducial method generateSquare.

private void generateSquare(int x0, int y0, int width, int value, GrayF32 image) {
    ImageMiscOps.fillRectangle(image, 0, x0, y0, width, width);
    int innerWidth = (int) (width * (1.0 - border * 2) + 0.5);
    int x1 = x0 + (width - innerWidth) / 2;
    int y1 = y0 + (width - innerWidth) / 2;
    expectedCorners.add(new Quadrilateral_F64(x0, y0, x0 + width, y0, x0 + width, y0 + width, x0, y0 + width));
    int bit = 0;
    for (int row = 0; row < binaryGrid; row++) {
        int pixelY0 = y1 + innerWidth - (row + 1) * innerWidth / binaryGrid;
        int pixelY1 = y1 + innerWidth - (row) * innerWidth / binaryGrid;
        for (int col = 0; col < binaryGrid; col++) {
            int pixelX0 = x1 + col * innerWidth / binaryGrid;
            int pixelX1 = x1 + (col + 1) * innerWidth / binaryGrid;
            boolean white;
            if (row == 0 && col == 0)
                white = false;
            else if (row == 0 && col == binaryGrid - 1)
                white = true;
            else if (row == binaryGrid - 1 && col == binaryGrid - 1)
                white = true;
            else if (row == binaryGrid - 1 && col == 0)
                white = true;
            else {
                white = ((value >> bit) & 0x01) == 0;
                bit++;
            }
            if (white) {
                ImageMiscOps.fillRectangle(image, 255, pixelX0, pixelY0, pixelX1 - pixelX0, pixelY1 - pixelY0);
            }
        }
    }
}
Also used : Quadrilateral_F64(georegression.struct.shapes.Quadrilateral_F64)

Aggregations

Quadrilateral_F64 (georegression.struct.shapes.Quadrilateral_F64)16 GrayF32 (boofcv.struct.image.GrayF32)4 Point2D_F64 (georegression.struct.point.Point2D_F64)4 Test (org.junit.jupiter.api.Test)4 FDistort (boofcv.abst.distort.FDistort)2 MediaManager (boofcv.io.MediaManager)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)2 Polygon2D_I32 (georegression.struct.shapes.Polygon2D_I32)2 BufferedImage (java.awt.image.BufferedImage)2 ConfigPointDetector (boofcv.abst.feature.detect.interest.ConfigPointDetector)1 PlToGrayMotion2D (boofcv.abst.sfm.d2.PlToGrayMotion2D)1 TrackerObjectQuad (boofcv.abst.tracker.TrackerObjectQuad)1 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)1 LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)1 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)1 FoundFiducial (boofcv.alg.fiducial.square.FoundFiducial)1 ConfigFiducialBinary (boofcv.factory.fiducial.ConfigFiducialBinary)1 ConfigPolygonDetector (boofcv.factory.shape.ConfigPolygonDetector)1 FactoryShapeDetector (boofcv.factory.shape.FactoryShapeDetector)1