Hardware Reference
In-Depth Information
2D Barcode Recognition Using a Webcam
In this project, you'll generate some two-
dimensional barcodes from text using an
online QR code generator. Then you'll decode
your tags using a camera and a computer.
Once this works, try decoding the QR code
illustrations in this topic.
MATERIALS
» Personal computer with uSb or FireWire port
» Web Access
» uSb or FireWire Webcam
» Printer
This sketch reads QR codes using a camera attached to a
personal computer. The video component is very similar to
the color-tracking example earlier. Before you start on the
sketch, though, you'll need some QR codes to read. Fortu-
nately, there are a number of QR code generators available
online. Just type the term into a search engine and see
how many pop up. There's a good one at http://qrcode.
kaywa.com , from which you can generate URLs, phone
numbers, or plain text. The more text you enter, the larger
the symbol. Generate a few codes and print them out for
use later. Save them as .png files, because you'll need them
for the sketch.
To run this sketch, you'll need to download the pqrcode
library for Processing by Daniel Shiffman, It's based on the
qrcode library from http://qrcode.sourceforge.jp. You can
download the pqrcode library from www.shiffman.net/p5/
pqrcode. Unzip it, and you'll get a directory called pqrcode.
Drop it into the libraries subdirectory of your Processing
application directory and restart Processing. Make a
new sketch, and within the sketch's directory, make a
subdirectory called data, and put in the .jpg or .png files of
the QR codes that you generated earlier. Now
you're ready to begin writing the sketch.
In the setup() for this sketch, you'll
import the pqrcode and OpenCV
libraries, and initialize a few global
variables.
8
/*
QRCode reader
Context: Processing
*/
import hypermedia.video.*;
import pqrcode.*;
OpenCV opencv; // instance of the opencv library
Decoder decoder; // instance of the pqrcode library
// a string to return messages:
String statusMsg = "Waiting for an image";
void setup() {
// initialize the window:
size(400, 320);
// initialize opencv:
opencv = new OpenCV( this );
opencv.capture( width, height );
// initialize the decoder:
decoder = new Decoder(this);
}
Search WWH ::




Custom Search