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.
IndexProgramming Questions & HelpVideo Capture,  Movie Playback,  Vision Libraries › background image in the "background substract
Page Index Toggle Pages: 1
background image in the "background substract (Read 330 times)
background image in the "background substract
Apr 9th, 2008, 9:54am
 
hei there!

i'd like to work with the "background substraction" excample.

import processing.video.*;

int numPixels;
int[] backgroundPixels;
Capture video;

void setup() {
 // Change size to 320 x 240 if too slow at 640 x 480
 size(640, 480);
 
 video = new Capture(this, width, height, 24);
 numPixels = video.width * video.height;
 // Create array to store the background image
 backgroundPixels = new int[numPixels];
 // Make the pixels[] array available for direct manipulation
 loadPixels();
}

void draw() {
 if (video.available()) {
   video.read(); // Read a new video frame
   video.loadPixels(); // Make the pixels of video available
   // Difference between the current frame and the stored background
   int presenceSum = 0;
   for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame...
     // Fetch the current color in that location, and also the color
     // of the background in that spot
     color currColor = video.pixels[i];
     color bkgdColor = backgroundPixels[i];
     // Extract the red, green, and blue components of the current pixel&#65533;s color
     int currR = (currColor >> 16) & 0xFF;
     int currG = (currColor >> 8) & 0xFF;
     int currB = currColor & 0xFF;
     // Extract the red, green, and blue components of the background pixel&#65533;s color
     int bkgdR = (bkgdColor >> 16) & 0xFF;
     int bkgdG = (bkgdColor >> 8) & 0xFF;
     int bkgdB = bkgdColor & 0xFF;
     // Compute the difference of the red, green, and blue values
     int diffR = abs(currR - bkgdR);
     int diffG = abs(currG - bkgdG);
     int diffB = abs(currB - bkgdB);
     // Add these differences to the running tally
     presenceSum += diffR + diffG + diffB;
     // Render the difference image to the screen
     pixels[i] = color(diffR, diffG, diffB);
     // The following line does the same thing much faster, but is more technical
     //pixels[i] = 0xFF000000 | (diffR << 16) | (diffG << 8) | diffB;
   }
   updatePixels(); // Notify that the pixels[] array has changed
   println(presenceSum); // Print out the total amount of movement
 }
}

// When a key is pressed, capture the background image into the backgroundPixels
// buffer, by copying each of the current frame&#65533;s pixels into it.
void keyPressed() {
 video.loadPixels();
 arraycopy(video.pixels, backgroundPixels);
}

what i'd like to do is to display on the keyPressed event a background image or another movie rather than the camera video!

can you help me with that?

thanks for your time!!! mias
Page Index Toggle Pages: 1