Search in sources :

Example 1 with QrCode

use of boofcv.alg.fiducial.qrcode.QrCode in project BoofCV by lessthanoptimal.

the class DetectQrCodeApp method processImage.

/**
 * Override this function so that it doesn't threshold the image twice
 */
@Override
public void processImage(int sourceID, long frameID, final BufferedImage buffered, ImageBase input) {
    System.out.flush();
    synchronized (bufferedImageLock) {
        original = ConvertBufferedImage.checkCopy(buffered, original);
        work = ConvertBufferedImage.checkDeclare(buffered, work);
    }
    if (saveRequested) {
        saveInputImage();
        saveRequested = false;
    }
    final double timeInSeconds;
    // TODO Copy all data that's visualized outside so that GUI doesn't lock
    synchronized (this) {
        long before = System.nanoTime();
        detector.process((T) input);
        long after = System.nanoTime();
        timeInSeconds = (after - before) * 1e-9;
    }
    // create a local copy so that gui and processing thread's dont conflict
    synchronized (detected) {
        this.detected.reset();
        for (QrCode d : detector.getDetections()) {
            this.detected.grow().set(d);
        }
        this.failures.reset();
        for (QrCode d : detector.getFailures()) {
            if (d.failureCause.ordinal() >= QrCode.Failure.READING_BITS.ordinal())
                this.failures.grow().set(d);
        }
    // System.out.println("Failed "+failures.size());
    // for( QrCode qr : failures.toList() ) {
    // System.out.println("  cause "+qr.failureCause);
    // }
    }
    controlPanel.polygonPanel.thresholdPanel.updateHistogram((T) input);
    SwingUtilities.invokeLater(() -> {
        controls.setProcessingTime(timeInSeconds);
        viewUpdated();
        synchronized (detected) {
            controlPanel.messagePanel.updateList(detected.toList(), failures.toList());
        }
    });
}
Also used : QrCode(boofcv.alg.fiducial.qrcode.QrCode) ConfigQrCode(boofcv.factory.fiducial.ConfigQrCode)

Example 2 with QrCode

use of boofcv.alg.fiducial.qrcode.QrCode in project BoofCV by lessthanoptimal.

the class DetectQrCodeMessagePanel method valueChanged.

@Override
public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting())
        return;
    if (e.getSource() == listDetected) {
        int selected = listDetected.getSelectedIndex();
        if (selected == -1)
            return;
        boolean failed = selected >= detected.size();
        if (failed) {
            selected -= detected.size();
            QrCode qr = failures.get(selected);
            listener.selectedMarkerInList(selected, true);
            setMarkerMessageText(qr, true);
        } else {
            listener.selectedMarkerInList(selected, false);
            QrCode qr = detected.get(selected);
            setMarkerMessageText(qr, false);
        }
        textArea.invalidate();
    }
}
Also used : QrCode(boofcv.alg.fiducial.qrcode.QrCode)

Example 3 with QrCode

use of boofcv.alg.fiducial.qrcode.QrCode in project BoofCV by lessthanoptimal.

the class GenericQrCodeDetectorChecks method renderAndCheck.

private void renderAndCheck(QrCodeDetector<GrayF32> detector, SimulatePlanarWorld simulator) {
    simulator.render();
    detector.process(simulator.getOutput());
    if (display) {
        ShowImages.showWindow(simulator.getOutput(), "Foo", true);
        BoofMiscOps.sleep(200);
        UtilImageIO.saveImage(simulator.getOutput(), "qrcode_rendered.png");
    }
    List<QrCode> detections = detector.getDetections();
    assertEquals(1, detections.size());
    QrCode qr = detections.get(0);
    assertEquals(message, new String(qr.message));
}
Also used : QrCode(boofcv.alg.fiducial.qrcode.QrCode)

Example 4 with QrCode

use of boofcv.alg.fiducial.qrcode.QrCode in project BoofCV by lessthanoptimal.

the class ExampleDetectQrCode method main.

public static void main(String[] args) {
    BufferedImage input = UtilImageIO.loadImage(UtilIO.pathExample("fiducial/qrcode/image01.jpg"));
    GrayU8 gray = ConvertBufferedImage.convertFrom(input, (GrayU8) null);
    QrCodeDetector<GrayU8> detector = FactoryFiducial.qrcode(null, GrayU8.class);
    detector.process(gray);
    // Get's a list of all the qr codes it could successfully detect and decode
    List<QrCode> 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 (QrCode 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<QrCode> failures = detector.getFailures();
    g2.setColor(Color.RED);
    for (QrCode qr : failures) {
        // If the 'cause' is ERROR_CORRECTION or later then it's probably a real QR Code that
        if (qr.failureCause.ordinal() < QrCode.Failure.ERROR_CORRECTION.ordinal())
            continue;
        VisualizeShapes.drawPolygon(qr.bounds, true, 1, g2);
    }
    ShowImages.showWindow(input, "Example QR Codes", true);
}
Also used : QrCode(boofcv.alg.fiducial.qrcode.QrCode) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 5 with QrCode

use of boofcv.alg.fiducial.qrcode.QrCode in project BoofCV by lessthanoptimal.

the class CreateQrCodeDocument method run.

public void run() throws IOException {
    if (messages == null || messages.size() == 0) {
        throw new RuntimeException("Need to specify a message");
    }
    getFileTypeFromFileName();
    if (fileType.equals("pdf")) {
        System.out.println("   Document     : PDF");
        System.out.println("   paper        : " + paperSize);
        System.out.println("   info         : " + (!disablePrintInfo));
        System.out.println("   units        : " + unit);
        System.out.println("   marker width : " + markerWidth + " (" + unit.abbreviation + ")");
    } else {
        System.out.println("   Document  : Image");
    }
    System.out.println();
    List<QrCode> markers = new ArrayList<>();
    for (String message : messages) {
        QrCodeEncoder encoder = new QrCodeEncoder();
        if (mask != null)
            encoder.setMask(mask);
        encoder.setError(error != null ? error : QrCode.ErrorLevel.M);
        if (version > 0)
            encoder.setVersion(version);
        if (encoding != null) {
            switch(encoding) {
                case NUMERIC:
                    encoder.addNumeric(message);
                    break;
                case ALPHANUMERIC:
                    encoder.addAlphanumeric(message);
                    break;
                case BYTE:
                    encoder.addBytes(message);
                    break;
                case KANJI:
                    encoder.addKanji(message);
                    break;
                default:
                    throw new RuntimeException("Unknown mode");
            }
        } else {
            encoder.addAutomatic(message);
        }
        QrCode qr = encoder.fixate();
        markers.add(qr);
        System.out.println("   Message");
        System.out.println("     length    : " + qr.message.length());
        System.out.println("     version   : " + qr.version);
        System.out.println("     encoding  : " + qr.mode);
        System.out.println("     error     : " + qr.error);
    }
    switch(fileType) {
        case "pdf":
            {
                CreateQrCodeDocumentPDF renderer = new CreateQrCodeDocumentPDF(fileName, paperSize, unit);
                renderer.markerWidth = markerWidth;
                renderer.spaceBetween = spaceBetween;
                renderer.gridFill = gridFill;
                renderer.showInfo = !hideInfo;
                renderer.render(markers);
                if (sendToPrinter) {
                    try {
                        renderer.sendToPrinter();
                    } catch (PrinterException e) {
                        throw new RuntimeException(e);
                    }
                } else
                    renderer.saveToDisk();
            }
            break;
        default:
            {
                CreateQrCodeDocumentImage renderer = new CreateQrCodeDocumentImage(fileName, 20);
                renderer.render(markers);
            }
            break;
    }
}
Also used : QrCode(boofcv.alg.fiducial.qrcode.QrCode) QrCodeEncoder(boofcv.alg.fiducial.qrcode.QrCodeEncoder) ArrayList(java.util.ArrayList) PrinterException(java.awt.print.PrinterException) CreateQrCodeDocumentImage(boofcv.app.qrcode.CreateQrCodeDocumentImage) CreateQrCodeDocumentPDF(boofcv.app.qrcode.CreateQrCodeDocumentPDF)

Aggregations

QrCode (boofcv.alg.fiducial.qrcode.QrCode)13 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)5 BufferedImage (java.awt.image.BufferedImage)5 GrayF32 (boofcv.struct.image.GrayF32)4 Test (org.junit.Test)4 QrCodeEncoder (boofcv.alg.fiducial.qrcode.QrCodeEncoder)2 ConfigQrCode (boofcv.factory.fiducial.ConfigQrCode)2 QrCodeGenerator (boofcv.alg.fiducial.qrcode.QrCodeGenerator)1 QrCodeGeneratorImage (boofcv.alg.fiducial.qrcode.QrCodeGeneratorImage)1 CreateQrCodeDocumentImage (boofcv.app.qrcode.CreateQrCodeDocumentImage)1 CreateQrCodeDocumentPDF (boofcv.app.qrcode.CreateQrCodeDocumentPDF)1 SimulatePlanarWorld (boofcv.simulation.SimulatePlanarWorld)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 PrinterException (java.awt.print.PrinterException)1 ArrayList (java.util.ArrayList)1