1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import processing.video.*; // Variable for video file Movie movie; // A variable for the color we are searching for. color trackColor; float thresh = 20; // threshold for the pixels we will change color randColor; // random color void setup() { size(640, 480); movie = new Movie(this, "aVideo.mov"); // load a movie movie.loop(); // Start off tracking for red trackColor = color(255, 0, 0); } void movieEvent (Movie m) { m.read(); } void draw() { loadPixels(); // load the pixels of the canvas movie.loadPixels(); // load the pixels of the movie // generate a random color for every frame of draw randColor = color(random(255), random(255), random(255)); // Begin loop to walk through every pixel for (int x = 0; x < movie.width; x ++ ) { for (int y = 0; y < movie.height; y ++ ) { int loc = x + y*movie.width; // What is current color color currentColor = movie.pixels[loc]; float r1 = red(currentColor); float g1 = green(currentColor); float b1 = blue(currentColor); float r2 = red(trackColor); float g2 = green(trackColor); float b2 = blue(trackColor); // Using euclidean distance to compare colors float d = dist(r1, g1, b1, r2, g2, b2); // We are using the dist( ) function to compare the current // color with the color we are tracking. // If current color less than the threshold, change it to the random color // if it'd greater, use the movie pixel if (d < thresh) { pixels[loc] = randColor; } else { pixels[loc] = currentColor; } } } updatePixels(); } void mousePressed() { // Save color where the mouse is clicked in trackColor variable int loc = mouseX + mouseY*movie.width; trackColor = movie.pixels[loc]; } |