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");
}
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");
}
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();
}
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());
}
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);
});
}
Aggregations