vitaminlite
YaBB Newbies
Offline
Posts: 1
Frame Differencing with PreRecorded Movie
Nov 10th , 2007, 7:32pm
Hello All, New to Processing here. I'm trying to use the Frame Differencing example in the Video (Capture) library but use a prerecorded film. When I run the code I get sound and it looks like I'm getting the movementSum in my println but no image appears. Below is my code. Any help would be much appreciated! import processing.video.*; int numPixels; int[] previousFrame; Movie myMovie; void setup() { size(460, 480, P3D); // Change size to 320 x 240 if too slow at 640 x 480 // Uses the default video input, see the reference if this causes an error background(0); myMovie = new Movie(this, "Matthew.mov"); numPixels = myMovie.width * myMovie.height; // Create an array to store the previously captured frame previousFrame = new int[numPixels]; loadPixels(); myMovie.loop(); } void draw() { { // When using video to manipulate the screen, use video.available() and // video.read() inside the draw() method so that it's safe to draw to the screen myMovie.read(); // Read the new frame from the camera myMovie.loadPixels(); // Make its pixels[] array available int movementSum = 0; // Amount of movement in the frame for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame... color currColor = myMovie.pixels[i]; color prevColor = previousFrame[i]; // Extract the red, green, and blue components from current pixel int currR = (currColor >> 16) & 0xFF; // Like red(), but faster int currG = (currColor >> 8) & 0xFF; int currB = currColor & 0xFF; // Extract red, green, and blue components from previous pixel int prevR = (prevColor >> 16) & 0xFF; int prevG = (prevColor >> 8) & 0xFF; int prevB = prevColor & 0xFF; // Compute the difference of the red, green, and blue values int diffR = abs(currR - prevR); int diffG = abs(currG - prevG); int diffB = abs(currB - prevB); // Add these differences to the running tally movementSum += diffR + diffG + diffB; // Render the difference image to the screen pixels[i] = color(diffR, diffG, diffB); // The following line is much faster, but more confusing to read //pixels[i] = 0xff000000 | (diffR << 16) | (diffG << 8) | diffB; // Save the current color into the 'previous' buffer previousFrame[i] = currColor; } // To prevent flicker from frames that are all black (no movement), // only update the screen if the image has changed. if (movementSum > 0) { updatePixels();//byte(255) if = 0, byte(0) . println(movementSum); // Print the total amount of movement to the console } } }