Difference between revisions of "Example Detect Micro QR Code"

From BoofCV
Jump to navigationJump to search
(Created page with "<center> <gallery widths=807px heights=331px> File:Example_micro_qr.jpg | Micro QR Code markers of different sizes are detected and out lned in red are detected in this image....")
 
m
 
Line 1: Line 1:
<center>
<center>
<gallery widths=807px heights=331px>
<gallery widths=807px heights=331px>
File:Example_micro_qr.jpg | Micro QR Code markers of different sizes are detected and out lned in red are detected in this image.
File:Example_micro_qr.jpg | Micro QR Code markers with various sizes are detected and outlined in red.
</gallery>
</gallery>
</center>
</center>

Latest revision as of 20:32, 17 January 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);
	}
}