Search in sources :

Example 1 with ConfigHammingMarker

use of boofcv.factory.fiducial.ConfigHammingMarker in project BoofCV by lessthanoptimal.

the class ExampleFiducialHamming method main.

public static void main(String[] args) {
    String directory = UtilIO.pathExample("fiducial/square_hamming/aruco_25h7");
    // load the lens distortion parameters and the input image
    CameraPinholeBrown param = CalibrationIO.load(new File(directory, "intrinsic.yaml"));
    LensDistortionNarrowFOV lensDistortion = new LensDistortionBrown(param);
    // You need to create a different configuration for each dictionary type
    ConfigHammingMarker configMarker = ConfigHammingMarker.loadDictionary(HammingDictionary.ARUCO_MIP_25h7);
    FiducialDetector<GrayF32> detector = FactoryFiducial.squareHamming(configMarker, /*detector*/
    null, GrayF32.class);
    // Provide it lens parameters so that a 3D pose estimate is possible
    detector.setLensDistortion(lensDistortion, param.width, param.height);
    // Load and process all example images
    ListDisplayPanel gui = new ListDisplayPanel();
    for (int imageID = 1; imageID <= 3; imageID++) {
        String name = String.format("image%02d.jpg", imageID);
        System.out.println("processing: " + name);
        // Load the image
        BufferedImage buffered = UtilImageIO.loadImageNotNull(new File(directory, name).getPath());
        // Convert to a BoofCV format
        GrayF32 input = ConvertBufferedImage.convertFrom(buffered, (GrayF32) null);
        // Run the detector
        detector.detect(input);
        // Render a 3D compute on top of all detections
        Graphics2D g2 = buffered.createGraphics();
        var targetToSensor = new Se3_F64();
        var locationPixel = new Point2D_F64();
        var bounds = new Polygon2D_F64();
        for (int i = 0; i < detector.totalFound(); i++) {
            detector.getCenter(i, locationPixel);
            detector.getBounds(i, bounds);
            g2.setColor(new Color(50, 50, 255));
            g2.setStroke(new BasicStroke(10));
            VisualizeShapes.drawPolygon(bounds, true, 1.0, g2);
            if (detector.hasID())
                System.out.println("Target ID = " + detector.getId(i));
            if (detector.hasMessage())
                System.out.println("Message   = " + detector.getMessage(i));
            System.out.println("2D Image Location = " + locationPixel);
            if (detector.is3D()) {
                detector.getFiducialToCamera(i, targetToSensor);
                System.out.println("3D Location:");
                System.out.println(targetToSensor);
                VisualizeFiducial.drawCube(targetToSensor, param, detector.getWidth(i), 3, g2);
                VisualizeFiducial.drawLabelCenter(targetToSensor, param, "" + detector.getId(i), g2);
            } else {
                VisualizeFiducial.drawLabel(locationPixel, "" + detector.getId(i), g2);
            }
        }
        gui.addImage(buffered, name, ScaleOptions.ALL);
    }
    ShowImages.showWindow(gui, "Example Fiducial Hamming", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) ConfigHammingMarker(boofcv.factory.fiducial.ConfigHammingMarker) LensDistortionBrown(boofcv.alg.distort.brown.LensDistortionBrown) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) GrayF32(boofcv.struct.image.GrayF32) Point2D_F64(georegression.struct.point.Point2D_F64) File(java.io.File) Se3_F64(georegression.struct.se.Se3_F64)

Example 2 with ConfigHammingMarker

use of boofcv.factory.fiducial.ConfigHammingMarker in project BoofCV by lessthanoptimal.

the class DetectFiducialSquareHammingApp method createDetector.

protected void createDetector(boolean initializing) {
    if (!initializing)
        BoofSwingUtil.checkGuiThread();
    synchronized (lockProcessing) {
        ConfigHammingMarker configMarker = controls.configMarker;
        ConfigFiducialHammingDetector configFid = controls.getDetectorConfig();
        final InputToBinary<GrayF32> binary = FactoryThresholdBinary.threshold(configFid.configThreshold, GrayF32.class);
        final DetectPolygonBinaryGrayRefine<GrayF32> squareDetector = FactoryShapeDetector.polygon(configFid.squareDetector, GrayF32.class);
        detector = new Detector(configMarker, configFid.minimumBlackBorderFraction, binary, squareDetector);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) FactoryShapeDetector(boofcv.factory.shape.FactoryShapeDetector) ConfigFiducialHammingDetector(boofcv.factory.fiducial.ConfigFiducialHammingDetector) ConfigHammingMarker(boofcv.factory.fiducial.ConfigHammingMarker) ConfigFiducialHammingDetector(boofcv.factory.fiducial.ConfigFiducialHammingDetector)

Aggregations

ConfigHammingMarker (boofcv.factory.fiducial.ConfigHammingMarker)2 GrayF32 (boofcv.struct.image.GrayF32)2 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)1 LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)1 ConfigFiducialHammingDetector (boofcv.factory.fiducial.ConfigFiducialHammingDetector)1 FactoryShapeDetector (boofcv.factory.shape.FactoryShapeDetector)1 ListDisplayPanel (boofcv.gui.ListDisplayPanel)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)1 Point2D_F64 (georegression.struct.point.Point2D_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1