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 › Frame differencing from a .mov - is it possible
Page Index Toggle Pages: 1
Frame differencing from a .mov - is it possible? (Read 1042 times)
Frame differencing from a .mov - is it possible?
Feb 13th, 2010, 12:54am
 
New to processing.

Can I do the above?

Thanks for your help.
Re: Frame differencing from a .mov - is it possible?
Reply #1 - Feb 13th, 2010, 1:18am
 
Please use the search form before asking questions! You would have found this by yourself :

http://processing.org/learning/libraries/framedifferencing.html
Re: Frame differencing from a .mov - is it possible?
Reply #2 - Feb 13th, 2010, 1:35am
 
Yes I did see this code but note that I wish to do frame differencing from a .mov video file not a webcam?
Re: Frame differencing from a .mov - is it possible?
Reply #3 - Feb 13th, 2010, 1:54am
 
Have a look at the reference : there's a built-in library to load Quicktime (.mov) videos.

http://processing.org/reference/libraries/video/index.html

I guess you can use the same method as in the FrameDifferecing example on the Movie object (movie.loadPixels(), movie.pixels[i]).
Re: Frame differencing from a .mov - is it possible?
Reply #4 - Feb 13th, 2010, 2:02am
 
Thanks for that. I guess I am looking for an existing sketch - just to make my life easier...but I will have a go...
Re: Frame differencing from a .mov - is it possible?
Reply #5 - Feb 13th, 2010, 8:14am
 
This is my go at 'Frame differencing a Mov' - just gets a grey screen output - no error messages - any suggestions please?

import processing.video.*;

int numPixels;
int[] previousFrame;
Movie myMovie;


void setup() {
 size(640, 480); // 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
 //video = new Capture(this, width, height, 24);
 myMovie = new Movie(this, "station.mov");

 numPixels = myMovie.width * myMovie.height;
 // Create an array to store the previously captured frame
 previousFrame = new int[numPixels];
 loadPixels();
}

void draw() {
 if (myMovie.available()) {
   // 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();
     println(movementSum); // Print the total amount of movement to the console
   }
 }
}
Re: Frame differencing from a .mov - is it possible?
Reply #6 - Feb 14th, 2010, 7:32am
 
You set the size of the window to 640x480. Check the size of the video source, or try :

Code:
size(myMovie.width, myMovie.height); 

Page Index Toggle Pages: 1