Manipulating pixels in a video
In the first recipe of this chapter, you've learned how to load a video file and display its frames to the screen using the image()
function. In this recipe, we'll take a look at how we can change the appearance of the movie by changing the color of some of the pixels.
How to do it...
The first part of the sketch will be similar to the example from the first recipe. Import the video
library, declare a Movie
object, load the video file, and loop it.
import processing.video.*; Movie m; int numPixels; void setup() { size( 640, 480 ); numPixels = width * height; m = new Movie( this, "marbles.mov" ); m.loop(); }
The big changes for this example are in the draw()
function. We'll draw each frame of the movie to the screen, using the image()
function. After doing that, we'll change the color of the pixels with a brightness higher than 245
.
void draw() { background( 0 ); image( m, 0, 0, width, height ); loadPixels(); for ( int i = 0; i <...