import processing.video.*; Movie myMovie; MovieMaker mm; float pos = 0.0; float step = 1.0 / 24; /* I created my own class because I was lazy--using the KDTree here would have meant making this file a .java file and losing some of the simplication processing provides because it doesn't like the <> template syntax in naive mode */ PointTree tree = new PointTree(); boolean newFrame = false; void setup() { size(320 ,200); background(0); // Load and play the video in a loop myMovie = new Movie(this, "dance.mov"); // this is the source movie, in this case I'm starting with a white on black movie. myMovie.loop(); // The pause() command is problematic for frame advance, // use this syntax instead. myMovie.speed(0); noLoop(); // I had to shut off the loop otherwise it would run faster than the movie and the frame degredation would trail off too quickly. mm = new MovieMaker(this, width, height, "new_dance.mov", 24, MovieMaker.H263, MovieMaker.HIGH); } void movieEvent(Movie myMovie) { myMovie.read(); newFrame = true; redraw(); // new data is available, so tell processing to draw it. } void draw() { if(! newFrame) return; // don't do any more drawing unless a new frame has been loaded in void movieEvent(...) else newFrame = false; //image(myMovie, 0, 0); myMovie.filter(THRESHOLD, 0.1); // thresholding to remove a watermark--I just used sample footage from a stock video site to test with. /* the center value of the kernel determins how solid the line is. If it is 12, it is a solid line; 8 is dotted/broken You'll have to experiment with this. */ float[][] kernel = { { -1, -2, -2 }, { -1, 8, -1 }, { -2, -2, -2 } }; //myMovie.loadPixels(); // Create an opaque image of the same size as the original PImage edgeImg = createImage(myMovie.width, myMovie.height, RGB); loadPixels(); edgeImg.loadPixels(); // Loop through every pixel in the image. for (int y = 1; y < myMovie.height-1; y++) { // Skip top and bottom edges for (int x = 1; x < myMovie.width-1; x++) { // Skip left and right edges float sum = 0; // Kernel sum for this pixel for (int ky = -1; ky <= 1; ky++) { for (int kx = -1; kx <= 1; kx++) { // Calculate the adjacent pixel for this kernel point int pos = (y + ky)*width + (x + kx); // Image is grayscale, red/green/blue are identical float val = red(myMovie.pixels[pos]); // Multiply adjacent pixels based on the kernel values sum += kernel[ky+1][kx+1] * val; } } // For this pixel in the new image, set the gray value // based on the sum from the kernel edgeImg.pixels[y*myMovie.width + x] = color(sum); } } // State that there are changes to edgeImg.pixels[] edgeImg.updatePixels(); //image(edgeImg, 0, 0); // Draw the new image edgeImg.loadPixels(); int ww = edgeImg.width; int hh = edgeImg.height; boolean pointFound = false; tree = new PointTree(); for(int i=0; i < edgeImg.height; i++) { for(int j=0; j < edgeImg.width; j++) { float p = red(edgeImg.pixels[i*ww + j]); if(p > 0) { if((j+i)%2==0) tree.addPoint(j,i); } } } double[] s = {0,0}; // the serach point. Start the search in the upper left corner each time double[] p = {0,0}; // the point retrieved beginShape(); while(tree.size() > 0) { p = tree.getNearestPoint(s); // get the nearest point curveVertex((float)p[0],(float)p[1]); // draw it s = p; // this point now becomes the next search point tree.removePoint(s); // remove the last one so it doesn't get found again, and cause a loop. } float _alpha = 20.0; //map(mouseX, 0, width, 0, 100); // alpha determines how quickly the old frames degrade or blend in with each other. float _blur = 0.3; //map(mouseY, 0, height, 0, 5); // the pixel radius of the gaussian blur which softens the old frames a bit fill(0, _alpha); // cover up the old frames noStroke(); rect(0,0,width,height); // cover the old frames noFill(); strokeWeight(.3); stroke(255); smooth(); filter(BLUR, _blur); // blur the old frames a bit endShape(); // finally, draw the new frame. mm.addFrame(); // add this new frame to the new movie // println("A:" + _alpha + " B:" + _blur); pos = (pos + step) % myMovie.duration(); // move the source footage counter forward a bit myMovie.jump(pos); // make the final jump } void keyPressed() { if(key == 'q') { mm.finish(); // write the output movie to disk exit(); } }