Tutorial QRCodes
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:
- Performance Study
- Detecting QR Codes Source Code YouTube
- Encoding QR Codes Source Code YouTube
- Encoding Application
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
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.