Search in sources :

Example 1 with ConfigAztecCode

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

the class ExampleDetectAztecCode method main.

public static void main(String[] args) {
    BufferedImage input = UtilImageIO.loadImageNotNull(UtilIO.pathExample("fiducial/aztec/image01.jpg"));
    GrayU8 gray = ConvertBufferedImage.convertFrom(input, (GrayU8) null);
    var config = new ConfigAztecCode();
    // config.considerTransposed = false; // by default, it will consider incorrectly encoded markers. Faster if false
    AztecCodePreciseDetector<GrayU8> detector = FactoryFiducial.aztec(config, GrayU8.class);
    detector.process(gray);
    // Gets a list of all the qr codes it could successfully detect and decode
    List<AztecCode> detections = detector.getDetections();
    // Print the encoded messages
    for (AztecCode marker : detections) {
        System.out.println("message: '" + marker.message + "'");
    }
    // Visualize the found markers in the image
    Graphics2D g2 = input.createGraphics();
    // in large images the line can be too thin
    int strokeWidth = Math.max(4, input.getWidth() / 200);
    g2.setColor(Color.GREEN);
    g2.setStroke(new BasicStroke(strokeWidth));
    for (AztecCode marker : detections) {
        VisualizeShapes.drawPolygon(marker.bounds, true, 1, g2);
    }
    // List of objects it thinks might be a QR Code but failed for various reasons
    List<AztecCode> failures = detector.getFailures();
    g2.setColor(Color.RED);
    for (AztecCode marker : failures) {
        // If it failed to decode the mode then there's a decent change of it being a false negative
        if (marker.failure.ordinal() < AztecCode.Failure.MODE_ECC.ordinal())
            continue;
        VisualizeShapes.drawPolygon(marker.bounds, true, 1, g2);
    }
    ShowImages.showWindow(input, "Example Aztec Codes", true);
}
Also used : ConfigAztecCode(boofcv.factory.fiducial.ConfigAztecCode) AztecCode(boofcv.alg.fiducial.aztec.AztecCode) ConfigAztecCode(boofcv.factory.fiducial.ConfigAztecCode) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

AztecCode (boofcv.alg.fiducial.aztec.AztecCode)1 ConfigAztecCode (boofcv.factory.fiducial.ConfigAztecCode)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 GrayU8 (boofcv.struct.image.GrayU8)1 BufferedImage (java.awt.image.BufferedImage)1