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