Search in sources :

Example 1 with FoundFiducial

use of boofcv.alg.fiducial.square.FoundFiducial in project BoofCV by lessthanoptimal.

the class VisualizeSquareBinaryFiducial 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));
    var undistorted = new GrayF32(input.width, input.height);
    InputToBinary<GrayF32> inputToBinary = FactoryThresholdBinary.globalOtsu(0, 255, 1.0, true, GrayF32.class);
    Detector detector = new Detector(gridWidth, borderWidth, inputToBinary);
    detector.setLengthSide(0.1);
    if (intrinsic != null) {
        CameraPinholeBrown 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);
        detector.process(undistorted);
    } else {
        detector.process(input);
    }
    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(VisualizeBinaryData.renderBinary(detector.squares.get(i), false, null), " " + i);
        squares.addImage(ConvertBufferedImage.convertTo(detector.squaresGray.get(i), null), " " + i);
    }
    BufferedImage output = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
    ConvertBufferedImage.convertTo(input, output);
    Graphics2D g2 = output.createGraphics();
    g2.setColor(Color.RED);
    g2.setStroke(new BasicStroke(2));
    for (int i = 0; i < N; i++) {
        VisualizeShapes.drawArrowSubPixel(fiducials.get(i).distortedPixels, 3, 1, g2);
    }
    ShowImages.showWindow(output, "Binary", true);
    ShowImages.showWindow(squares, "Candidates", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) LensDistortionBrown(boofcv.alg.distort.brown.LensDistortionBrown) 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 2 with FoundFiducial

use of boofcv.alg.fiducial.square.FoundFiducial in project BoofCV by lessthanoptimal.

the class DetectFiducialSquareGrid method detect.

/**
 * Searches for the fiducial inside the image.
 * If at least a partial match is found true is returned.
 *
 * @param input Input image
 * @return true if at least one of the component fiducials is detected. False otherwise
 */
public boolean detect(T input) {
    detections.reset();
    detector.process(input);
    DogArray<FoundFiducial> found = detector.getFound();
    for (int i = 0; i < found.size(); i++) {
        FoundFiducial fid = found.get(i);
        int gridIndex = isExpected(fid.id);
        if (gridIndex >= 0) {
            Detection d = lookupDetection(fid.id, gridIndex);
            d.location.setTo(fid.distortedPixels);
            d.numDetected++;
        }
    }
    for (int i = detections.size - 1; i >= 0; i--) {
        if (detections.get(i).numDetected != 1) {
            detections.remove(i);
        }
    }
    return detections.size > 0;
}
Also used : FoundFiducial(boofcv.alg.fiducial.square.FoundFiducial)

Example 3 with FoundFiducial

use of boofcv.alg.fiducial.square.FoundFiducial 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 4 with FoundFiducial

use of boofcv.alg.fiducial.square.FoundFiducial in project BoofCV by lessthanoptimal.

the class SquareBase_to_FiducialDetector method getBounds.

@Override
public Polygon2D_F64 getBounds(int which, @Nullable Polygon2D_F64 storage) {
    if (storage == null)
        storage = new Polygon2D_F64();
    else
        storage.vertexes.reset();
    FoundFiducial found = getAlgorithm().getFound().get(which);
    storage.vertexes.grow().setTo(found.distortedPixels.a);
    storage.vertexes.grow().setTo(found.distortedPixels.b);
    storage.vertexes.grow().setTo(found.distortedPixels.c);
    storage.vertexes.grow().setTo(found.distortedPixels.d);
    return storage;
}
Also used : FoundFiducial(boofcv.alg.fiducial.square.FoundFiducial) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 5 with FoundFiducial

use of boofcv.alg.fiducial.square.FoundFiducial in project BoofCV by lessthanoptimal.

the class SquareBase_to_FiducialDetector method getDetectedControl.

@Override
public List<PointIndex2D_F64> getDetectedControl(int which) {
    FoundFiducial found = getAlgorithm().getFound().get(which);
    listQuad.get(0).p.setTo(found.distortedPixels.a);
    listQuad.get(1).p.setTo(found.distortedPixels.b);
    listQuad.get(2).p.setTo(found.distortedPixels.c);
    listQuad.get(3).p.setTo(found.distortedPixels.d);
    return listQuad;
}
Also used : FoundFiducial(boofcv.alg.fiducial.square.FoundFiducial)

Aggregations

FoundFiducial (boofcv.alg.fiducial.square.FoundFiducial)5 LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)2 ConfigPolygonDetector (boofcv.factory.shape.ConfigPolygonDetector)2 FactoryShapeDetector (boofcv.factory.shape.FactoryShapeDetector)2 ListDisplayPanel (boofcv.gui.ListDisplayPanel)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 CameraPinhole (boofcv.struct.calib.CameraPinhole)2 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)2 GrayF32 (boofcv.struct.image.GrayF32)2 BufferedImage (java.awt.image.BufferedImage)2 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)1 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)1 Quadrilateral_F64 (georegression.struct.shapes.Quadrilateral_F64)1