Difference between revisions of "Example Detect Micro QR Code"
From BoofCV
Jump to navigationJump to searchm |
m |
||
Line 15: | Line 15: | ||
Relevant Examples/Tutorials: | Relevant Examples/Tutorials: | ||
* [https://www.ninox360.com/barcode-scanner 2D Barcode Webapp] | |||
* [[Tutorial_QRCodes|Tutorial QR Codes]] | * [[Tutorial_QRCodes|Tutorial QR Codes]] | ||
* [[Example_Render_Micro_QR_Code|Rendering Micro QR Codes]] | * [[Example_Render_Micro_QR_Code|Rendering Micro QR Codes]] |
Latest revision as of 08:49, 10 November 2022
Micro QR Codes are designed to be smaller and more space efficient than regular QR codes. They are not as compact as Datamatrix, but have an easier to identify locator pattern making them more appropriate in complex scenes.
Example Code:
Concepts:
- Fiducials
- QR Codes
Relevant Examples/Tutorials:
Example Code
/**
* Shows you how to detect a Micro QR Code inside an image and process the extracted data. Much of the information that
* is computed while detecting and decoding a QR Code is saved inside the {@link MicroQrCode} class. This can be useful
* for application developers.
*
* @author Peter Abeles
*/
public class ExampleDetectMicroQrCode {
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();
int strokeWidth = Math.max(4, input.getWidth()/200); // in large images the line can be too thin
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);
}
}