We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
copy bug? or my mistake? (Read 787 times)
copy bug? or my mistake?
Sep 2nd, 2005, 6:38pm
 
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 :)
Re: copy bug? or my mistake?
Reply #1 - Sep 3rd, 2005, 2:22pm
 
If it's comparing two images you're looking for, this thread might help:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=VideoCamera;action=display;num=1117150396

enjoy and good luck Smiley

-seltar
Page Index Toggle Pages: 1