Difference between revisions of "Tutorial QRCodes"

From BoofCV
Jump to navigationJump to search
m
m
Line 1: Line 1:
[[File:Example_qrcode_detection.jpg|center|frame]]
[[File:Example_qrcode_detection.jpg|center|frame]]


BoofCV provides methods for decoding and creating QR Codes. QR Codes is short for Quick Response Codes and you can find more out about them on [https://en.wikipedia.org/wiki/QR_code wikipedia]. QR Codes are widely used in factories, consumer products, computer applications as a way to transmit text, such as a website's address or a part number, reliably using a camera.
QR Codes is short for Quick Response Codes and you can find more out about them on [https://en.wikipedia.org/wiki/QR_code wikipedia]. QR Codes are widely used in factories, consumer products, computer applications as a way to transmit text, such as a website's address or a part number, reliably using a camera.


BoofCV provides various pre-built tools for scanning and decoding QR codes from images, as well as a programmer API for doing the same. The scanner included with BoofCV is one of the best performing open source libraries, see the performance study link below. The QR Code generator included with BoofCV is designed to be flexible and generate standards compliant markers. Many of the random QR Code generators found online actually generate non standards compliant markers in weird ways which will reduce the number of scanners that work on them. For example, I've seen tools which generate markers with the bits inverted!
Quick Reference Links:
* [[Performance:QrCode | Performance Study]]
* [[Performance:QrCode | Performance Study]]
* Detecting QR Codes [[Example_Detect_QR_Code|Source Code]] [https://youtu.be/TGg-xgTyaU8?t=272 YouTube]
* Detecting QR Codes [[Example_Detect_QR_Code|Source Code]] [https://youtu.be/TGg-xgTyaU8?t=272 YouTube]
Line 9: Line 12:
* Encoding Application
* Encoding Application


The detector provided in BoofCV was designed to be able to process large images and yet still detect small qr codes reliably under a variety of conditions. It's of to a good start but needs more work to handle blurred images and QR codes with damaged position patterns. It has several nice features. The current code base was adopted from camera calibration code and will provide very precise estimate of the corners on a qr code. This can be used estimate the marker's 3D pose relative to the camera more accurately than with other libraries. Failures can also be accessed. It's not unusual to detect a qr code but to have there be too many read errors to correctly decode it.
The remainder of this short tutorial will focus on applications. For how to program your own tool using BoofCV see the links above to code examples. The demonstration application is good if you would like to see visualizations of intermediate steps when decoding a QR Code. This is useful if you wish to understand why it failed to detect a QR code.


Tools for processing and generating QR Codes are included with BoofCV. You can download the pre-build application from the [[Applications| Applications Website.]]
If you have not already done so, you should now download the pre-build application from the [[Applications| Applications Website.]].


== Generating QR Codes ==
== Generating QR Codes ==

Revision as of 08:57, 20 July 2021

Example qrcode detection.jpg

QR Codes is short for Quick Response Codes and you can find more out about them on wikipedia. QR Codes are widely used in factories, consumer products, computer applications as a way to transmit text, such as a website's address or a part number, reliably using a camera.

BoofCV provides various pre-built tools for scanning and decoding QR codes from images, as well as a programmer API for doing the same. The scanner included with BoofCV is one of the best performing open source libraries, see the performance study link below. The QR Code generator included with BoofCV is designed to be flexible and generate standards compliant markers. Many of the random QR Code generators found online actually generate non standards compliant markers in weird ways which will reduce the number of scanners that work on them. For example, I've seen tools which generate markers with the bits inverted!

Quick Reference Links:

The remainder of this short tutorial will focus on applications. For how to program your own tool using BoofCV see the links above to code examples. The demonstration application is good if you would like to see visualizations of intermediate steps when decoding a QR Code. This is useful if you wish to understand why it failed to detect a QR code.

If you have not already done so, you should now download the pre-build application from the Applications Website..

Generating QR Codes

Screenshot of QR Code Creator application.

Both command line and GUI tools are provided. QR Code creation tool included with BoofCV is very flexible and lets you customize almost everything about a standards compliant QR code. Here is a summary of some of the their features:

  • Select output document type
  • Select prebuilt paper sizes or specify a custom one
  • Specify the QR Code size under various units
  • Force different encoding and other low level QR code settings
  • Advanced options for batch printing on a single document

A screenshot of the GUI tool is shown above. As you type it will generate the results live and same codes for when you modify different settings. Both GUI and command line tools allow you to generate a grid of markers for when you need to mass produce them.

To launch the GUI type the following:

java -jar applications.jar --GUI

Then select "QR Code" under "Create / Print".

To run the command line tools type what is shown below and it will print out detailed help.

java -jar applications.jar CreateQrCodeDocument


Batch Scanning

Batch scanning can be accomplished using a command line interface or GUI. Paths can be specified directly, or using glob/regex patterns. Directories will be recursively searched. After you have downloaded or built the applications jar you can run it with the following command:

java -jar applications/applications.jar BatchScanQrCodes

This will print out the latest and most up to date usage information. Next you will need to add arguments that specify what it should process, and a few examples are listed below:

-i /path/to/directory -o myresults.txt
   Finds all images in 'path/to' directory
-i "regex:path/to/\w+\.jpg" -o myresults.txt
   Finds all files ending with .jpg in 'path/to' directory
-i "glob:path/to/*.jpg" -o myresults.txt
   Finds all files ending with .jpg in 'path/to' directory
-i "glob:path/**/*" -o myresults.txt
   Recursively search all directories starting at 'path' for images

Just to be clear, to run one of those commands you need to pass it into the BatchScanQrCodes application as follows:

java -jar applications/applications.jar BatchScanQrCodes -i "glob:data/example/fiducial/**/*" -o myresults.txt
<syntaxhighlight lang="bash">
That example will scan all the fiducials example images for QR codes and dump the results to "myresults.txt". On my computer it takes about 2 seconds to run.

=== GUI ===

The GUI is really just a light weight wrapper on top of the command line interface. To launch that type:
<syntaxhighlight lang="bash">
java -jar applications/applications.jar --GUI

Then press the "Batch QR Code" button.

Programming