Im having a brain-freeze moment... I can't figure out how to use two PImage vars to compare the current image coming from the video camera to the image from the previous frame.
Heres the trimmed down version of the code Im working with:
Code://Globals
import processing.video.*;
Capture cam;
PImage scene, prevScene, diffScene;
void setup(){
int FPS=15;
int dimX=800;
int dimY=600;
size(dimX,dimY);
scene = new PImage(dimX, dimY);
prevScene = new PImage(dimX, dimY);
diffScene = new PImage(dimX, dimY);
cam = new Capture(this, dimX, dimY, FPS);
}
void draw(){
if(cam.available()){
// set the prevScene to equal scene
prevScene = scene;
/*
Using PImage.copy() doesn't seem to work
prevScene.copy(scene,0,0,cam.width, cam.height,0,0,cam.width,cam.height);
*/
//grab the new image from the video camera
cam.read();
// update the current scene var with the new camera image
scene=cam;
// scene.copy(cam,0,0,cam.width,cam.height,0,0,cam.width,cam.height);
// look for differences
for(int i=0; i<scene.pixels.length; i++){
diffScene.pixels[i]=(scene.pixels[i] == prevScene.pixels[i]) ? color(255) : color(0);
}
// print images to the screen
image(diffScene,width-530,height-100,120,90);
image(prevScene,width-330,height-100,120,90);
image(scene,width-130,height-100,120,90);
}
}
I started out by trying to use copy() to move the pixels to and from the PImage vars but that didn't seem to work so I'm using a direct association now (eg. prevFrame = currentFrame; currentFrame = Image from camera) and it doesn't look like that's working for me either.
Is this related to the copy() bug or is it a mistake on my end? Im betting on coder error :)