Frame Differencing Tricks with Processing

I haven’t been posting anything lately but I have a lot helpful bits of code backlogged on my machine and I am going to try to share and explain some. This first section has to do with frame differencing. The purpose of frame differencing is to constantly check the way each frame in a movie or video changes and respond accordingly. For instance, you could use frame differencing to track something that is moving on screen. That is basically what this piece of software does. It has a “palette” frame in which only moving pixels are drawn to the screen. This creates an interesting effect. Here is the source code : frame_diff_movie.pde. I also have a ‘live’ version that does this algorithm in real-time on webcam input available here : frame_diff.pde.
Here is a brief rundown on how the code itself operates. First you chose a reference frame by hitting the space bar. You usually want to do this when the movie is only showing the background and the subject has not yet moved or entered the frame. This frame is stored in [ int[] previousFrame ]. Now every-time a new frame is read from the movie file, our algorithm compares each pixel in the new frame to each corresponding pixel in the old frame. If the movementSum (amount of movement in the frame) is greater than the globally defined TOLERANCE integer, it draws that pixel to the screen. You can hit the ‘r’ to start recording into a video output and hit ’s’ to close the outgoing movie stream. Here is a video of my friend Christian trying to write his name on his bike:

http://www.vimeo.com/1282940

4 comments ↓

#1 alba on 09.13.08 at 3:41 pm

this is great!!!!

#2 howard on 10.09.08 at 9:57 am

hey, i tried this out but when i run it, the applet stays blank and nothing happens. if you could help me out, that would be swell.

#3 benjamin on 10.10.08 at 7:33 am

@Howard,

It depends on which applet you are running. If you are using frame_diff_movie, make sure you have specified an available movie file. If you are using the live version, frame_diff, you may need to do some work to choose an input source. Reply with more info and I can help you. Let me know which one you are trying to use, which platform you are on, do you have a builtin webcam, are there any errors, etc.

#4 Dennis Finegan on 05.06.09 at 7:40 pm

So cool. Probably will never use it, but just to know it’s out there is enough. Thanks.

Leave a Comment