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
compare pixels (Read 755 times)
compare pixels
Jan 3rd, 2007, 11:38am
 
hello,
i want to compare the pixels of two consecutive frames. with my code i only get a black screen, so i guess i made a mistake in the draw method.
thx for your help,
martina



import processing.video.*;

Movie myMovie;
color lastFramesColors[], thisFramesColors[];


void setup()
{
 size(640, 480);
 background(0);
 // Load and play the video in a loop
 myMovie = new Movie(this, "MartinaSinging.mov");
 myMovie.loop();

 thisFramesColors = new color[width*height];
 lastFramesColors =  new color[width*height];
}


void movieEvent(Movie myMovie) {
 //copy this frame's pixels into last frame's pixels
 for(int k=0; k<thisFramesColors.length; k++) {
   lastFramesColors[k] = thisFramesColors[k] ;
 }

 //copy this frame's pixels into arr thisFramesColors[]  
 myMovie.read();
 for(int i=0; i<height; i++) {
   for(int j=0; j<width; j++) {
     thisFramesColors[i * width + j] = myMovie.get(j,i);
   }
 }
}


void draw() {  
 //compare pixels of this and last frame and color them
 for(int i=0; i<height; i++) {
   for(int j=0; j<width; j++) {
     if(thisFramesColors[i * width + j] != lastFramesColors[i * width + j]){
       fill(255,0,0);
       rect(j,i,5,5);
     }
     else{
       fill(255,255,255);
       rect(j,i,5,5);
     }
   }
 }
}

Re: compare pixels
Reply #1 - Jan 3rd, 2007, 4:03pm
 
just a guess:

myMovie.read();
myMovie.loadPixels(); // since Movie extends PImage

F
Page Index Toggle Pages: 1