Search in sources :

Example 1 with ConfigUchiyaMarker

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

the class TestCreateFiducialUchiya method case0.

@Test
void case0() throws IOException {
    int N = 4;
    createDocument("--MarkerBorder -w 8 -um 4 -n 30 -o uchiya.pdf");
    BufferedImage image = loadPDF();
    GrayU8 gray = new GrayU8(image.getWidth(), image.getHeight());
    ConvertBufferedImage.convertFrom(image, gray);
    ConfigUchiyaMarker config = new ConfigUchiyaMarker();
    config.markerWidth = 8.0;
    config.markerHeight = 8.0;
    Uchiya_to_FiducialDetector<GrayU8> detector = FactoryFiducial.randomDots(config, GrayU8.class);
    Random rand = new Random(defaults.randomSeed);
    for (int i = 0; i < N; i++) {
        detector.addMarker(RandomDotMarkerGenerator.createRandomMarker(rand, 30, config.markerWidth, config.markerHeight, defaults.dotDiameter));
    }
    detector.detect(gray);
    checkResults(N, detector);
}
Also used : Random(java.util.Random) GrayU8(boofcv.struct.image.GrayU8) ConfigUchiyaMarker(boofcv.factory.fiducial.ConfigUchiyaMarker) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Test(org.junit.jupiter.api.Test)

Example 2 with ConfigUchiyaMarker

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

the class TestCreateFiducialUchiya method case1.

@Test
void case1() throws IOException {
    int N = 8;
    createDocument("-rs 4445 -w 5 -um 8 -n 22 -dd 0.6 -o uchiya.pdf");
    BufferedImage image = loadPDF();
    GrayU8 gray = new GrayU8(image.getWidth(), image.getHeight());
    ConvertBufferedImage.convertFrom(image, gray);
    // ShowImages.showBlocking(gray, "Foo", 5_000);
    ConfigUchiyaMarker config = new ConfigUchiyaMarker();
    config.markerWidth = 5.0;
    config.markerHeight = 5.0;
    Uchiya_to_FiducialDetector<GrayU8> detector = FactoryFiducial.randomDots(config, GrayU8.class);
    Random rand = new Random(4445);
    for (int i = 0; i < N; i++) {
        detector.addMarker(RandomDotMarkerGenerator.createRandomMarker(rand, 22, config.markerWidth, config.markerHeight, 0.6));
    }
    detector.detect(gray);
    checkResults(N, detector);
}
Also used : Random(java.util.Random) GrayU8(boofcv.struct.image.GrayU8) ConfigUchiyaMarker(boofcv.factory.fiducial.ConfigUchiyaMarker) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigUchiyaMarker

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

the class TestCreateFiducialUchiya method rectangleMarker.

@Test
void rectangleMarker() throws IOException {
    int N = 4;
    createDocument("--MarkerBorder -w 5 -h 10 -um 4 -n 30 -o uchiya.pdf");
    BufferedImage image = loadPDF();
    GrayU8 gray = new GrayU8(image.getWidth(), image.getHeight());
    ConvertBufferedImage.convertFrom(image, gray);
    ConfigUchiyaMarker config = new ConfigUchiyaMarker();
    config.markerWidth = 5.0;
    config.markerHeight = 10.0;
    Uchiya_to_FiducialDetector<GrayU8> detector = FactoryFiducial.randomDots(config, GrayU8.class);
    Random rand = new Random(defaults.randomSeed);
    for (int i = 0; i < N; i++) {
        detector.addMarker(RandomDotMarkerGenerator.createRandomMarker(rand, 30, config.markerWidth, config.markerHeight, defaults.dotDiameter));
    }
    detector.detect(gray);
    checkResults(N, detector);
}
Also used : Random(java.util.Random) GrayU8(boofcv.struct.image.GrayU8) ConfigUchiyaMarker(boofcv.factory.fiducial.ConfigUchiyaMarker) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigUchiyaMarker

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

the class ExampleFiducialRandomDots method main.

public static void main(String[] args) {
    // The definitions file specifies where dots are on each marker and other bits of meta data
    RandomDotDefinition defs = FiducialIO.loadRandomDotYaml(UtilIO.fileExample("fiducial/random_dots/descriptions.yaml"));
    // The only parameter that you have to set is markerLength. It's used to compute bounding
    // boxes and similar. If you don't know what the width is just set it to 1.0
    var config = new ConfigUchiyaMarker();
    config.markerWidth = defs.markerWidth;
    config.markerHeight = defs.markerHeight;
    Uchiya_to_FiducialDetector<GrayU8> detector = FactoryFiducial.randomDots(config, GrayU8.class);
    // Load / learn all the markers. This can take a few seconds if there are a lot of markers
    for (List<Point2D_F64> marker : defs.markers) {
        detector.addMarker(marker);
    }
    // If you want 3D pose information then the camera need sto be calibrated. If you don't provide
    // this information then just things like the bounding box will be returned
    CameraPinholeBrown intrinsic = CalibrationIO.load(UtilIO.fileExample("fiducial/random_dots/intrinsic.yaml"));
    detector.setLensDistortion(LensDistortionFactory.narrow(intrinsic), intrinsic.width, intrinsic.height);
    // It's now ready to start processing images. Let's load an image
    BufferedImage image = UtilImageIO.loadImageNotNull(UtilIO.pathExample("fiducial/random_dots/image02.jpg"));
    GrayU8 gray = ConvertBufferedImage.convertFrom(image, false, ImageType.SB_U8);
    detector.detect(gray);
    // Time to visualize the results
    Graphics2D g2 = image.createGraphics();
    var targetToSensor = new Se3_F64();
    var bounds = new Polygon2D_F64();
    var center = new Point2D_F64();
    for (int i = 0; i < detector.totalFound(); i++) {
        detector.getBounds(i, bounds);
        detector.getCenter(i, center);
        g2.setColor(new Color(50, 50, 255));
        g2.setStroke(new BasicStroke(10));
        VisualizeShapes.drawPolygon(bounds, true, 1.0, g2);
        VisualizeFiducial.drawLabel(center, "" + detector.getId(i), g2);
        System.out.println("Target ID = " + detector.getId(i));
        if (detector.is3D()) {
            detector.getFiducialToCamera(i, targetToSensor);
            VisualizeFiducial.drawCube(targetToSensor, intrinsic, detector.getWidth(i), 3, g2);
        }
    }
    ShowImages.showWindow(image, "Random Dot Markers", true);
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) RandomDotDefinition(boofcv.io.fiducial.RandomDotDefinition) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) GrayU8(boofcv.struct.image.GrayU8) ConfigUchiyaMarker(boofcv.factory.fiducial.ConfigUchiyaMarker) Se3_F64(georegression.struct.se.Se3_F64)

Aggregations

ConfigUchiyaMarker (boofcv.factory.fiducial.ConfigUchiyaMarker)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)4 GrayU8 (boofcv.struct.image.GrayU8)4 BufferedImage (java.awt.image.BufferedImage)4 Random (java.util.Random)3 Test (org.junit.jupiter.api.Test)3 RandomDotDefinition (boofcv.io.fiducial.RandomDotDefinition)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