We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everybody,
Today, I found the QRCode library from Daniel Shiffman with the following code:
/*
QRcode reader
Generate images from a QRcode generator such as
http://qrcode.kaywa.com/ and put them in this sketch's
data folder.
Press spacebar to read from the camera, generate an image,
and scan for barcodes. Press f to read from a file and scan.
Press s for camera settings.
Created 9 June 2007
by Tom Igoe / Daniel Shiffman
*/
import processing.video.*;
import qrcodeprocessing.*;
Capture video; // instance of the video capture library
String statusMsg = "Waiting for an image"; // a string to return messages:
// Decoder object from prdecoder library
Decoder decoder;
void setup() {
size(400, 320);
video = new Capture(this, 320, 240);
video.start();
// Create a decoder object
decoder = new Decoder(this);
}
// When the decoder object finishes
// this method will be invoked.
void decoderEvent(Decoder decoder) {
statusMsg = decoder.getDecodedString();
}
void captureEvent(Capture video) {
video.read();
}
void draw() {
background(0);
// Display video
image(video, 0, 0);
// Display status
text(statusMsg, 10, height-4);
// If we are currently decoding
if (decoder.decoding()) {
// Display the image being decoded
PImage show = decoder.getImage();
image(show, 0, 0, show.width/4, show.height/4);
statusMsg = "Decoding image";
for (int i = 0; i < (frameCount/2) % 10; i++) statusMsg += ".";
}
}
void keyReleased() {
// Depending on which key is hit, do different things:
switch (key) {
case ' ':
// Spacebar takes a picture and tests it:
// copy it to the PImage savedFrame:
PImage savedFrame = createImage(video.width, video.height, RGB);
savedFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
savedFrame.updatePixels();
// Decode savedFrame
decoder.decodeImage(savedFrame);
break;
case 'f': // f runs a test on a file
PImage preservedFrame = loadImage("qrcode.png");
// Decode file
decoder.decodeImage(preservedFrame);
break;
}
}
But if Ioad it, the 'Capture video' (line 4 here, normally line 17) is underlined red and is says: 'The class 'Capture' does not exist'.
Does anybody knows how to fix this? I'm using Processing 3 by the way.
Is it possible to make this code compatible with Android? If I load this code in Android mode, there are no errors in the PDE, but if I run it, it crashes. How can I fix this?
Regards, Daantje
Answers
Instead of posting the code as a quote, try posting it as a code (highlight +ctrl+o). That way we'll be able to read the code and thereby helping you with you issue.
Thank you, I've edited my first post. The problem is that Processing says 'The class Capture does not exist' (line 17). I'm using the example from the library, without something edited.
I hope someone can now help me with my problem. Regards, Daantje!
I have already found my problem: I did not installed the Processing Video library!
But now, I have another question: Is it possible to make this code compatible with Android? If I load this code in Android mode, there are no errors in the PDE, but if I run it, it crashes. How can I fix this?
Regards, Daantje
@Daantje===
can you put your exact code when "there are no errors in the PDE" (because trying the first one fires a lot of errors for me)
after some modifs now it runs and does not crash
of course the onReleased() part cannot run as it is: you have to add some button with listener or motionEvents like double tap or long press.
you cannot use the video P5 capture with android
it is probably possible to use the camera object from android but i think that the best way is to work with google play service which has classes for qrcode.
@Daantje===
i have tried to add some button+listener. When you click it fires a fatal error because this lib uses java.awt.image.BufferedImage which is not supported by android... So in this case i do choose the google play service way...