Search in sources :

Example 1 with ConfigMicroQrCode

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

the class ExampleDetectMicroQrCode method main.

public static void main(String[] args) {
    BufferedImage input = UtilImageIO.loadImageNotNull(UtilIO.pathExample("fiducial/microqr/image01.jpg"));
    GrayU8 gray = ConvertBufferedImage.convertFrom(input, (GrayU8) null);
    var config = new ConfigMicroQrCode();
    // config.considerTransposed = false; // by default, it will consider incorrectly encoded markers. Faster if false
    MicroQrCodeDetector<GrayU8> detector = FactoryFiducial.microqr(config, GrayU8.class);
    detector.process(gray);
    // Gets a list of all the qr codes it could successfully detect and decode
    List<MicroQrCode> detections = detector.getDetections();
    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 (MicroQrCode qr : detections) {
        // The message encoded in the marker
        System.out.println("message: '" + qr.message + "'");
        // Visualize its location in the image
        VisualizeShapes.drawPolygon(qr.bounds, true, 1, g2);
    }
    // List of objects it thinks might be a QR Code but failed for various reasons
    List<MicroQrCode> failures = detector.getFailures();
    g2.setColor(Color.RED);
    for (MicroQrCode qr : failures) {
        // If the 'cause' is ERROR_CORRECTION or later it might a real QR Code
        if (qr.failureCause.ordinal() < QrCode.Failure.ERROR_CORRECTION.ordinal())
            continue;
        VisualizeShapes.drawPolygon(qr.bounds, true, 1, g2);
    }
    ShowImages.showWindow(input, "Example Micro QR Codes", true);
}
Also used : GrayU8(boofcv.struct.image.GrayU8) ConfigMicroQrCode(boofcv.factory.fiducial.ConfigMicroQrCode) ConfigMicroQrCode(boofcv.factory.fiducial.ConfigMicroQrCode) MicroQrCode(boofcv.alg.fiducial.microqr.MicroQrCode) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

MicroQrCode (boofcv.alg.fiducial.microqr.MicroQrCode)1 ConfigMicroQrCode (boofcv.factory.fiducial.ConfigMicroQrCode)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 GrayU8 (boofcv.struct.image.GrayU8)1 BufferedImage (java.awt.image.BufferedImage)1