Search in sources :

Example 6 with ConfigFiducialBinary

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

the class TestDetectFiducialSquareGrid method simple.

/**
 * Generate a fiducial and detect its corners.  Fully visible.
 */
@Test
public 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.Test)

Example 7 with ConfigFiducialBinary

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

the class TestCreateFiducialSquareBinary method single.

@Test
public void single() throws IOException, InterruptedException {
    int expected = 234;
    createDocument(String.format("-PrintInfo -PrintGrid -PageSize=letter -OutputFile=%s 3 %d", document_name + ".pdf", expected));
    GrayF32 gray = loadImageGray();
    ConfigFiducialBinary config = new ConfigFiducialBinary(30);
    FiducialDetector<GrayF32> detector = FactoryFiducial.squareBinary(config, configThreshold, GrayF32.class);
    detector.detect(gray);
    assertEquals(1, detector.totalFound());
    assertEquals(expected, detector.getId(0));
}
Also used : ConfigFiducialBinary(boofcv.factory.fiducial.ConfigFiducialBinary) GrayF32(boofcv.struct.image.GrayF32) Test(org.junit.Test)

Example 8 with ConfigFiducialBinary

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

the class TestCreateFiducialSquareBinary method customized.

/**
 * Adjust the border and the number of grid elements
 */
@Test
public void customized() throws IOException, InterruptedException {
    int[] expected = new int[] { 234, 23233 };
    double border = 0.1;
    int gridWidth = 5;
    createDocument(String.format("-BlackBorder=%f -BinaryGridWidth=%d -Grid=fill -PageSize=letter -OutputFile=%s 3 %d %d", border, gridWidth, document_name + ".pdf", expected[0], expected[1]));
    GrayF32 gray = loadImageGray();
    ConfigFiducialBinary config = new ConfigFiducialBinary(30);
    config.borderWidthFraction = border;
    config.gridWidth = gridWidth;
    FiducialDetector<GrayF32> detector = FactoryFiducial.squareBinary(config, configThreshold, GrayF32.class);
    detector.detect(gray);
    assertEquals(9, detector.totalFound());
    for (int i = 0; i < detector.totalFound(); i++) {
        assertEquals(expected[i % 2], detector.getId(i));
    }
}
Also used : ConfigFiducialBinary(boofcv.factory.fiducial.ConfigFiducialBinary) GrayF32(boofcv.struct.image.GrayF32) Test(org.junit.Test)

Example 9 with ConfigFiducialBinary

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

the class ExampleFiducialBinary method main.

public static void main(String[] args) {
    String directory = UtilIO.pathExample("fiducial/binary");
    // load the lens distortion parameters and the input image
    CameraPinholeRadial param = CalibrationIO.load(new File(directory, "intrinsic.yaml"));
    LensDistortionNarrowFOV lensDistortion = new LensDistortionRadialTangential(param);
    BufferedImage input = UtilImageIO.loadImage(directory, "image0000.jpg");
    // BufferedImage input = UtilImageIO.loadImage(directory , "image0001.jpg");
    // BufferedImage input = UtilImageIO.loadImage(directory , "image0002.jpg");
    GrayF32 original = ConvertBufferedImage.convertFrom(input, true, ImageType.single(GrayF32.class));
    // Detect the fiducial
    FiducialDetector<GrayF32> detector = FactoryFiducial.squareBinary(new ConfigFiducialBinary(0.1), ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 21), GrayF32.class);
    // new ConfigFiducialBinary(0.1), ConfigThreshold.fixed(100),GrayF32.class);
    detector.setLensDistortion(lensDistortion, param.width, param.height);
    detector.detect(original);
    // print the results
    Graphics2D g2 = input.createGraphics();
    Se3_F64 targetToSensor = new Se3_F64();
    Point2D_F64 locationPixel = new Point2D_F64();
    Polygon2D_F64 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.hasUniqueID())
            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);
        }
    }
    ShowImages.showWindow(input, "Fiducials", true);
}
Also used : ConfigFiducialBinary(boofcv.factory.fiducial.ConfigFiducialBinary) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) LensDistortionRadialTangential(boofcv.alg.distort.radtan.LensDistortionRadialTangential) GrayF32(boofcv.struct.image.GrayF32) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) Point2D_F64(georegression.struct.point.Point2D_F64) File(java.io.File) Se3_F64(georegression.struct.se.Se3_F64)

Aggregations

ConfigFiducialBinary (boofcv.factory.fiducial.ConfigFiducialBinary)9 GrayF32 (boofcv.struct.image.GrayF32)6 Test (org.junit.Test)4 ConfigThreshold (boofcv.factory.filter.binary.ConfigThreshold)3 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2 SquareImage_to_FiducialDetector (boofcv.abst.fiducial.SquareImage_to_FiducialDetector)1 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)1 ConfigFiducialImage (boofcv.factory.fiducial.ConfigFiducialImage)1 FactoryShapeDetector (boofcv.factory.shape.FactoryShapeDetector)1 PathLabel (boofcv.io.PathLabel)1 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)1 GrayU8 (boofcv.struct.image.GrayU8)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 Quadrilateral_F64 (georegression.struct.shapes.Quadrilateral_F64)1 BufferedReader (java.io.BufferedReader)1