//live video tracking & manipulation for theatre performance //final project: ICM, Fall 2005, by Ed Purver //this code uses Sonia library by Amit Pitaru, Blob Detection library by v3ga, and the video library for Processing //many thanks to Dan Shiffman for invaluable help at every step on the way //import libraries import processing.video.*; import blobDetection.*; import pitaru.sonia_v2_9.*; //declare global variables float level; int x = 0; int y = 0; int w; int h; int t = 20; float bx; float by; Capture video; Capture video2; PImage img; boolean newFrame=false; boolean policeman = false; boolean freeze = false; //bult in blob detection class BlobDetection theBlobDetection; Blob b; //declare 2D array Tile[][] tiles = new Tile[t][t]; void setup() { //display settings size(320, 240); colorMode(RGB, 255, 255, 255, 100); //check to see what video sources are available println(Capture.list()); //variables for live video input String s = Capture.list()[0]; String j = Capture.list()[1]; video = new Capture(this, s, width, height, 12); video2 = new Capture(this, j, width, height, 12); w = video.width/t; h = video.height/t; //call built-in function for Sonia library Sonia.start(this); LiveInput.start(); //loop through 2D array to create PImages for (int x = 0; x < t; x++) { for (int y = 0; y < t; y++) { tiles[x][y] = new Tile(w*x,h*y); } } // BlobDetection img = new PImage(80,60); // img which will be sent to detection (a smaller copy of the cam frame); theBlobDetection = new BlobDetection(img.width, img.height); theBlobDetection.setPosDiscrimination(true); theBlobDetection.setThreshold(0.95f); // will detect bright areas whose luminosity > 0.95f; } //function to capture live video void captureEvent(Capture video) { video.read(); newFrame = true; } void draw() { //manual controls for background if (keyCode == ENTER) { background(0); } else { } //initialize sound level input value level = LiveInput.getLevel(); //println(level); //set key control for freeze effect if (key == '2') { freeze = true; } else { freeze = false; } if (freeze == true) { //go through the array and call functions to copy video into PImage, draw the PImage array and add movement/tracking for (int x = 0; x < t; x++) { for (int y = 0; y < t; y++) { if(dist(bx,by,x*w,y*h) < 50) { tiles[x][y].chunk.copy(video, w * x, h *y, w, h, 0, 0, w, h); tiles[x][y].chunk.updatePixels(); tiles[x][y].render(); tiles[x][y].move(); if(key == '1') { tiles[x][y].jiggle(level); } } } } } else { //go through the array and call functions to copy video into PImage, draw the PImage array and add movement/tracking for (int x = 0; x < t; x++) { for (int y = 0; y < t; y++) { tiles[x][y].chunk.copy(video, w * x, h *y, w, h, 0, 0, w, h); tiles[x][y].chunk.updatePixels(); tiles[x][y].render(); tiles[x][y].move(); if(key == '1') { tiles[x][y].jiggle(level); } } } } if (newFrame) { newFrame=false; //image(video,0,0,width,height); img.copy(video2, 0, 0, video2.width, video2.height, 0, 0, img.width, img.height); //fastblur(img, 2); theBlobDetection.computeBlobs(img.pixels); drawBlobsAndEdges(true); } } void drawBlobsAndEdges(boolean drawBlobs) { noFill(); if( theBlobDetection.getBlobNb() ==0) { for (int x = 0; x < t; x++) { for (int y = 0; y < t; y++) { tiles[x][y].dragged = false; } } policeman = false; } Blob b; for (int n=0 ; n