Hardware Reference
In-Depth Information
The draw() method draws the
camera image and prints a status
message to the screen. If the decoder
library is in the middle of reading an
image, it displays that image in the
upper-lefthand corner, and changes the
status message.
8
void draw() {
// read the camera:
opencv.read();
// show the camera image:
image( opencv.image(), 0, 0 );
// Display status message:
text(statusMsg, 10, height-4);
// If you're currently decoding:
if (decoder.decoding()) {
// Display the image being decoded:
PImage show = decoder.getImage();
image(show, 0, 0, show.width/4, show.height/4);
// update the status message:
statusMsg = "Decoding image";
// add a dot after every tenth frame:
for (int dotCount = 0; dotCount < (frameCount) % 10; dotCount++) {
statusMsg += ".";
}
}
}
8
The pqrcode library has a method
called decodeImage() . To use it, pass it
an image in the keyReleased() method.
A switch statement checks to see
which key has been pressed. If you type
f , it passes the decoder a file called
qrcode.png from the data subdirectory.
If you press the space bar, it passes the
camera image. If you type s , it brings
up a camera settings dialog box.
void keyReleased() {
String code = "";
// Depending on which key is hit, do different things:
switch (key) {
case ' ': // space bar takes a picture and tests it:
// Decode the image:
decoder.decodeImage(opencv.image());
break;
case 'f': // f runs a test on a file
PImage preservedFrame = loadImage("qrcode.png");
// Decode the file
decoder.decodeImage(preservedFrame);
break;
}
}
Once you've given the decoder an
image, you wait. When it's decoded
the image, it generates a decoder-
Event() , and you can read the tag's ID
using the getDecodedString() method.
8
// When the decoder object finishes
// this method will be invoked.
void decoderEvent(Decoder decoder) {
statusMsg = decoder.getDecodedString();
}
 
Search WWH ::




Custom Search