Example Detect Aztec Code

From BoofCV
Revision as of 16:28, 2 September 2022 by Peter (talk | contribs) (Created page with "<center> <gallery widths=807px heights=331px> File:Example_aztec_code_scan.jpg | Aztec Code marker detected on a ticket. </gallery> </center> [https://en.wikipedia.org/wiki/A...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Aztec Codes are popular in transportation and related industries. They can encode a lot of information and don't require a quite zone around the marker. However, due to the lack of easily identified landmarks, larger markers are harder to scan.

Example Code:


  • Fiducials
  • QR Codes

Relevant Examples/Tutorials:

Example Code

 * Shows you how to detect an Aztec Code inside an image. BoofCV provides a lot of information about the marker and
 * provides an accurate location of the finder pattern. For example, you can get the number of bit errors which
 * were encountered while reading and will return failed detections with the reason they failed.
 * @author Peter Abeles
public class ExampleDetectAztecCode {
	public static void main( String[] args ) {
		BufferedImage input = UtilImageIO.loadImageNotNull(UtilIO.pathExample("fiducial/aztec/image01.jpg"));
		GrayU8 gray = ConvertBufferedImage.convertFrom(input, (GrayU8)null);

		var config = new ConfigAztecCode();
//		config.considerTransposed = false; // by default, it will consider incorrectly encoded markers. Faster if false
		AztecCodePreciseDetector<GrayU8> detector = FactoryFiducial.aztec(config, GrayU8.class);


		// Gets a list of all the qr codes it could successfully detect and decode
		List<AztecCode> detections = detector.getDetections();

		// Print the encoded messages
		for (AztecCode marker : detections) {
			System.out.println("message: '" + marker.message + "'");

		// Visualize the found markers in the image
		Graphics2D g2 = input.createGraphics();
		int strokeWidth = Math.max(4, input.getWidth()/200); // in large images the line can be too thin
		g2.setStroke(new BasicStroke(strokeWidth));
		for (AztecCode marker : detections) {
			VisualizeShapes.drawPolygon(marker.bounds, true, 1, g2);

		// List of objects it thinks might be a QR Code but failed for various reasons
		List<AztecCode> failures = detector.getFailures();
		for (AztecCode marker : failures) {
			// If it failed to decode the mode then there's a decent change of it being a false negative
			if (marker.failure.ordinal() < AztecCode.Failure.MODE_ECC.ordinal())

			VisualizeShapes.drawPolygon(marker.bounds, true, 1, g2);

		ShowImages.showWindow(input, "Example Aztec Codes", true);