Search in sources :

Example 6 with QrCode

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

the class TestCreateQrCodeDocument method two.

@Test
public void two() throws IOException, InterruptedException {
    createDocument("-t http://boofcv.org -t second -p LETTER -w 5 -o target.pdf");
    BufferedImage image = loadImage();
    GrayF32 gray = new GrayF32(image.getWidth(), image.getHeight());
    ConvertBufferedImage.convertFrom(image, gray);
    // ShowImages.showWindow(image,"Rendered", true);
    // BoofMiscOps.sleep(10000);
    QrCodeDetector<GrayF32> detector = FactoryFiducial.qrcode(null, GrayF32.class);
    detector.process(gray);
    List<QrCode> found = detector.getDetections();
    assertEquals(2, found.size());
    checkFound(found, "http://boofcv.org", "second");
}
Also used : QrCode(boofcv.alg.fiducial.qrcode.QrCode) GrayF32(boofcv.struct.image.GrayF32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) Test(org.junit.Test)

Example 7 with QrCode

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

the class TestCreateQrCodeDocument method gridAndCustomDocument.

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

Example 8 with QrCode

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

the class CreateQrCodeDocumentPDF method render.

public void render(java.util.List<QrCode> markers) throws IOException {
    if (markerWidth <= 0 || spaceBetween <= 0)
        throw new RuntimeException("Must specify the marker's dimensions. Width and spacing");
    printHeader();
    float sizeBox = (markerWidth + spaceBetween) * UNIT_TO_POINTS;
    int numRows = (int) Math.floor(pageHeight / sizeBox);
    int numCols = (int) Math.floor(pageWidth / sizeBox);
    if (!gridFill) {
        numRows = Math.max(1, markers.size() / numCols);
        if (numRows == 1) {
            numCols = Math.max(1, markers.size() % numCols);
        }
    }
    // offset used to center
    float centerX = (pageHeight - sizeBox * numRows) / 2f;
    float centerY = (pageWidth - sizeBox * numCols) / 2f;
    int index = 0;
    Generator g = new Generator(markerWidth * UNIT_TO_POINTS);
    for (int row = 0; row < numRows; row++) {
        g.offsetY = centerX + row * sizeBox + UNIT_TO_POINTS * spaceBetween / 2f;
        for (int col = 0; col < numCols; col++, index++) {
            if (!gridFill && index >= markers.size())
                break;
            QrCode qr = markers.get(index % markers.size());
            g.offsetX = centerY + col * sizeBox + UNIT_TO_POINTS * spaceBetween / 2f;
            g.render(qr);
            if (showInfo) {
                float offset = UNIT_TO_POINTS * spaceBetween / 4f;
                int maxLength = (int) (markerWidth * UNIT_TO_POINTS) / 4;
                String message = qr.message.toString();
                if (message.length() > maxLength) {
                    message = message.substring(0, maxLength);
                }
                pcs.beginText();
                pcs.setNonStrokingColor(Color.GRAY);
                pcs.setFont(PDType1Font.TIMES_ROMAN, 7);
                pcs.newLineAtOffset((float) g.offsetX, (float) g.offsetY - offset);
                pcs.showText(message);
                pcs.endText();
                pcs.beginText();
                pcs.newLineAtOffset((float) g.offsetX, (float) g.offsetY + markerWidth * UNIT_TO_POINTS + offset - 7);
                pcs.showText(String.format("%4.1f %2s", markerWidth, units.getAbbreviation()));
                pcs.endText();
            }
        }
    }
    pcs.close();
}
Also used : QrCode(boofcv.alg.fiducial.qrcode.QrCode) QrCodeGenerator(boofcv.alg.fiducial.qrcode.QrCodeGenerator)

Example 9 with QrCode

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

the class GenericQrCodeDetectorChecks method multipleMarkers.

/**
 * See if it can detect multiple markers in the image at the same time
 */
@Test
public void multipleMarkers() {
    QrCodeDetector<GrayF32> detector = createDetector();
    CameraPinholeRadial model = CalibrationIO.load(getClass().getResource("calib/pinhole_radial.yaml"));
    SimulatePlanarWorld simulator = new SimulatePlanarWorld();
    simulator.setCamera(model);
    simulator.resetScene();
    Se3_F64 markerToWorld0 = new Se3_F64();
    Se3_F64 markerToWorld1 = new Se3_F64();
    simulator.addTarget(markerToWorld0, simulatedTargetWidth, generateMarker());
    simulator.addTarget(markerToWorld1, simulatedTargetWidth, generateMarker());
    markerToWorld0.T.set(0.2, 0, 0.6);
    markerToWorld1.T.set(-0.2, 0, 0.6);
    simulator.render();
    detector.process(simulator.getOutput());
    if (display) {
        ShowImages.showWindow(simulator.getOutput(), "Foo", true);
        BoofMiscOps.sleep(10000);
    }
    List<QrCode> detections = detector.getDetections();
    assertEquals(2, detections.size());
}
Also used : QrCode(boofcv.alg.fiducial.qrcode.QrCode) SimulatePlanarWorld(boofcv.simulation.SimulatePlanarWorld) GrayF32(boofcv.struct.image.GrayF32) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Example 10 with QrCode

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

the class DetectQrCodeApp method selectedMarkerInList.

@Override
public void selectedMarkerInList(int index, boolean failure) {
    double width = 0;
    final Point2D_F64 center = new Point2D_F64();
    synchronized (detected) {
        QrCode qr;
        if (failure) {
            if (index >= failures.size)
                return;
            qr = failures.get(index);
        } else {
            if (index >= detected.size)
                return;
            qr = detected.get(index);
        }
        UtilPolygons2D_F64.vertexAverage(qr.bounds, center);
        for (int i = 0; i < 4; i++) {
            width = Math.max(width, qr.bounds.getSideLength(i));
        }
    }
    final double _width = width;
    BoofSwingUtil.invokeNowOrLater(() -> {
        double scale = 0.75 * Math.min(gui.getWidth(), gui.getHeight()) / _width;
        gui.setScaleAndCenter(scale, center.x, center.y);
        controlPanel.setZoom(scale);
    });
}
Also used : QrCode(boofcv.alg.fiducial.qrcode.QrCode) ConfigQrCode(boofcv.factory.fiducial.ConfigQrCode) Point2D_F64(georegression.struct.point.Point2D_F64)

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