We are about to switch to a new forum software. Until then we have removed the registration on this forum.
import processing.video.*;
Capture cam;
PImage img;
void setup(){
size(640*2, 480*2);
cam = new Capture(this);
cam.start();
img = createImage(640, 480, RGB);
}
void draw() {
if (cam.available()) {
cam.read();
}
cam.loadPixels();
image(cam, 0, 0);
img.loadPixels();
if (cam.pixels.length>0){
for(int i = 0; i<640*480; i++){
float r = red(cam.pixels[i]);
float g = green(cam.pixels[i]);
float b = blue(cam.pixels[i]);
img.pixels[i] = color(r,g,b);
}
image(img, 640, 480);
}
print("works..");
}
That's the code. yet all i get on the 'img' displayed is the first frame frozen from the cam. The print 'works' however repeatedly prints, and i do not understand why should the cam.read() also repeatedly work and thus provide img with the full stream of frames. (The natural cam display - image(cam, 0, 0) works well).
any advice?
Answers
http://processing.org/reference/PImage_updatePixels_.html