Difference between revisions of "Example Detect Aztec Code"

From BoofCV
Jump to navigationJump to search
m
m
 
Line 15: Line 15:


Relevant Examples/Tutorials:
Relevant Examples/Tutorials:
* [https://www.ninox360.com/barcode-scanner 2D Barcode Webapp]
* [[Example_Render_Aztec_Code|Rendering Aztec Codes]]
* [[Example_Render_Aztec_Code|Rendering Aztec Codes]]
* [[Example_Detect_QR_Code|QR Codes]]
* [[Example_Detect_QR_Code|QR Codes]]

Latest revision as of 08:49, 10 November 2022

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:

Concepts:

  • 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);

		detector.process(gray);

		// 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.setColor(Color.GREEN);
		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();
		g2.setColor(Color.RED);
		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())
				continue;

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

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