Search in sources :

Example 6 with MicroQrCode

use of boofcv.alg.fiducial.microqr.MicroQrCode in project BoofCV by lessthanoptimal.

the class DetectMicroQrMessagePanel method updateList.

public void updateList(List<MicroQrCode> detected, List<MicroQrCode> failures) {
    BoofSwingUtil.checkGuiThread();
    this.listDetected.removeListSelectionListener(this);
    DefaultListModel<String> model = (DefaultListModel) listDetected.getModel();
    model.clear();
    this.detected.clear();
    for (int i = 0; i < detected.size(); i++) {
        MicroQrCode qr = detected.get(i);
        model.addElement(String.format("v%2d Mode %.5s %.10s", qr.version, qr.mode.toString(), qr.message));
        this.detected.add(qr.clone());
    }
    this.failures.clear();
    for (int i = 0; i < failures.size(); i++) {
        MicroQrCode qr = failures.get(i);
        model.addElement(String.format("v%2d Cause: %s", qr.version, qr.failureCause.toString()));
        this.failures.add(qr.clone());
    }
    listDetected.invalidate();
    listDetected.repaint();
    textArea.setText("");
    this.listDetected.addListSelectionListener(this);
}
Also used : MicroQrCode(boofcv.alg.fiducial.microqr.MicroQrCode)

Example 7 with MicroQrCode

use of boofcv.alg.fiducial.microqr.MicroQrCode 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)

Example 8 with MicroQrCode

use of boofcv.alg.fiducial.microqr.MicroQrCode in project BoofCV by lessthanoptimal.

the class CreateMicroQrDocumentPDF method render.

@Override
protected void render(int markerIndex) {
    MicroQrCode qr = markers.get(markerIndex % markers.size());
    g.render(qr);
}
Also used : MicroQrCode(boofcv.alg.fiducial.microqr.MicroQrCode)

Example 9 with MicroQrCode

use of boofcv.alg.fiducial.microqr.MicroQrCode in project BoofCV by lessthanoptimal.

the class ExampleRenderMicroQrCode method main.

public static void main(String[] args) {
    // Uses a flow pattern to specify the QR Code. You can control all aspects of the Micro QR
    // like specifying the version, mask, and message types or let it select all of that for you.
    MicroQrCode qr = new MicroQrCodeEncoder().setError(MicroQrCode.ErrorLevel.L).addAutomatic("Test ん鞠").fixate();
    // NOTE: The final function you call must be fixate(), that's how it knows it's done
    // Render the QR as an image. It's also possible to render as a PDF or your own custom format
    GrayU8 rendered = MicroQrCodeGenerator.renderImage(/* pixel per module */
    10, /* border modules*/
    1, qr);
    // Convert it to a BufferedImage for display purposes
    BufferedImage output = ConvertBufferedImage.convertTo(rendered, null);
    // You can also save it to disk by uncommenting the line below
    // UtilImageIO.saveImage(output, "microqr.png");
    // Display the image
    ShowImages.showWindow(output, "Rendered Micro QR Code", true);
}
Also used : MicroQrCode(boofcv.alg.fiducial.microqr.MicroQrCode) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) MicroQrCodeEncoder(boofcv.alg.fiducial.microqr.MicroQrCodeEncoder)

Example 10 with MicroQrCode

use of boofcv.alg.fiducial.microqr.MicroQrCode in project BoofCV by lessthanoptimal.

the class TestCreateMicroQrDocument method gridAndCustomDocument.

@Test
void gridAndCustomDocument() throws IOException {
    createDocument("-t 1234567 -t second -p 14cm:14cm --GridFill -w 5 -o target.pdf");
    BufferedImage image = loadPDF();
    var gray = new GrayF32(image.getWidth(), image.getHeight());
    ConvertBufferedImage.convertFrom(image, gray);
    // ShowImages.showWindow(image,"Rendered", true);
    // BoofMiscOps.sleep(10000);
    MicroQrCodeDetector<GrayF32> detector = FactoryFiducial.microqr(null, GrayF32.class);
    detector.process(gray);
    List<MicroQrCode> found = detector.getDetections();
    assertEquals(4, found.size());
    checkFound(detector.getDetections(), "1234567", "second");
}
Also used : GrayF32(boofcv.struct.image.GrayF32) MicroQrCode(boofcv.alg.fiducial.microqr.MicroQrCode) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Test(org.junit.jupiter.api.Test)

Aggregations

MicroQrCode (boofcv.alg.fiducial.microqr.MicroQrCode)14 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)6 BufferedImage (java.awt.image.BufferedImage)6 GrayF32 (boofcv.struct.image.GrayF32)4 Test (org.junit.jupiter.api.Test)4 MicroQrCodeEncoder (boofcv.alg.fiducial.microqr.MicroQrCodeEncoder)3 GrayU8 (boofcv.struct.image.GrayU8)3 FDistort (boofcv.abst.distort.FDistort)1 FiducialImageEngine (boofcv.alg.drawing.FiducialImageEngine)1 MicroQrCodeGenerator (boofcv.alg.fiducial.microqr.MicroQrCodeGenerator)1 ConfigMicroQrCode (boofcv.factory.fiducial.ConfigMicroQrCode)1 SimulatePlanarWorld (boofcv.simulation.SimulatePlanarWorld)1 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)1 Se3_F64 (georegression.struct.se.Se3_F64)1 Random (java.util.Random)1