Diewald library capturing one QR at a time issue

edited March 2014 in Library Questions

I'm using the following script to extract multiple QR codes from my webcam:

The code runs fine and detects multiple QR codes on my regular lenovo laptop webcam. However, for some reason, when I utilize an external microsoft lifecam hd-3000, the program just recognizes one QR code at a time (hence I have to have just one QR code on the screen for it to be recognized).

Would you happen to have heard of such a bizarre issue? Your feedback is much appreciated

import diewald_bardcode.*;
import diewald_bardcode.CONSTANTS.*;
import codeanticode.gsvideo.*;

GSCapture cam;
int cam_size_x = 640;// 1280;//1280;//800; //1280;
int cam_size_y = 480;// 720;//800;//600; //(int)(3.0*cam_size_x/4.0);

PFont font;

// SETUP
// ——————————————————————————————————–
void setup()
{
font = createFont("Arial", 20);
textFont(font);

size(cam_size_x, cam_size_y);

String[] cameras = GSCapture.list();
cam = new GSCapture(this, 640, 480,30); // …, cam_size_y, cameras[1] ) <– If multiple Cameras are used!
cam.start();

// uncomment this to see your supported Camera Resolutions!
// println ("Supported Resolution:");
// int[][] res = cam.resolutions();
// for (int i = 0; i < res.length; i++) {
// println(res[i][0] + "x" + res[i][1]);
// }
}

// DRAW
// ——————————————————————————————————–
void draw()
{

if ( cam.available() ) {
background(0);
cam.read();
cam.loadPixels();
image(cam, 0, 0);
decode();
}
}

// Decode QR Code
// ——————————————————————————————————–
void decode() {

DecodingResult[] dr = Barcode.decodeMultiQRcode(cam, CHARACTER_SET.DEFAULT, true); //true = tryHarder (slower)

for (int QR_count = 0; QR_count < dr.length; QR_count++) {

if ( dr[QR_count].decodingFailed() == true) {
fill(255, 0, 0);
text( "No decoding information could be found!", 20, 40 );
}

else {
fill (0, 255, 0);

int xpos = int(dr[QR_count].getCorners()[0].x);
int ypos = int(dr[QR_count].getCorners()[0].y);

text(dr[QR_count].getText(), xpos, ypos);

for (int PosIndex = 0; PosIndex < 3; PosIndex++) {
int NewX = int(dr[QR_count].getCorners()[PosIndex].x);
int NewY = int(dr[QR_count].getCorners()[PosIndex].y);

pushMatrix();
translate(NewX-10, NewY-10);
rect(0, 0, 20, 20);
popMatrix();
}
}
}
}

Answers

  • Why don't you enqueue all of the the PImage objects in a List?
    Then deal w/ them in a more appropriate time! (%)

  • thank you for your prompt response,

    It would be great if you can provide me a code to do that, because i am having trouble with the above library to convert from capture to PImage and then to the Decode function.

    thank you

  • edited March 2014

    I believe GSCapture should be a subclass of PImage. Otherwise you wouldn't be able to directly use it as an image() argument!

    BtW, plz highlight your posted code and hit CTRL+K in order to properly format it! :-\"

  • edited March 2014

    I've just tried the following alteration to no avail. Any more suggestions? Thanks!

    PImage img;
    
    void draw()
    {
    
    if ( cam.available() ) {
    background(0);
    cam.read();
    cam.loadPixels();
    image(cam, 0, 0);
    img=cam;
    decode();
    }
    }
    void decode() {
    DecodingResult[] dr = Barcode.decodeMultiQRcode(img, CHARACTER_SET.DEFAULT, true); //true = tryHarder (slower)
    ...}
    
  • edited March 2014

    I've meant a List of PImage objects! (~~)

    // forum.processing.org/two/discussion/3810/
    // diewald-library-capturing-one-qr-at-a-time-issue
    
    final ArrayList<PImage> imgs = new ArrayList();
    GSCapture cam;
    
    void setup() {
      size(640, 480, JAVA2D);
      frameRate(60);
    
      ( cam = new GSCapture(this, width, height, 30) ).start();
    }
    
    void draw() {
      if (!cam.available()) {
        dequeue();  // decodes oldest entry!
        return;
      }
    
      imgs.add(cam.read()); // otherwise enqueue latest PImage!
      background(cam);
    }
    
  • edited March 2014

    Hey thank you for your quick response. I just tried the following (again, same result ):

    final ArrayList<PImage> imgs = new ArrayList();
    
    void draw()
    {
    
    if ( cam.available() ) {
    background(0);
    cam.read();
    cam.loadPixels();
    image(cam, 0, 0);
    imgs.add(cam);
    decode();
    }
    }
    
    void decode() {
    
    DecodingResult[] dr = Barcode.decodeMultiQRcode(imgs.get(imgs.size()-1), CHARACTER_SET.DEFAULT, true); //true = tryHarder (slower)
    ...
    }
    
  • Cool emoticons btw :P

Sign In or Register to comment.