/** * * Doing some stuff with video. */ // port forwarding if you need it: // ssh -L 3306:localhost:3306 rtwomey@192.168.0.183 import hypermedia.video.*; import java.awt.Rectangle; import de.bezier.data.sql.*; import processing.video.*; import codeanticode.gsvideo.*; GSMovie myMovie; Gaggle agents; // ---- face tracking stuff ---- PImage img; PImage frameimg; PFont font; int filenum=257; int facenum=0; int frame=0; int id=0; int startframe=0; int newFrame=0; float moviepos=0.0; float lasttime=0; // ---- interactivity ---- // // timing int last=0; boolean paused=false; String DETECTION_CASCADE=OpenCV.CASCADE_FRONTALFACE_DEFAULT; //String DETECTION_CASCADE=OpenCV.CASCADE_FRONTALFACE_ALT_TREE; //String DETECTION_CASCADE=OpenCV.CASCADE_PROFILEFACE; //String inpath="/Volumes/external/tera/Assets/Memory/20080630 930pm - breaking up with nichol/"; String inpath="/Volumes/Reservoir/Assets/Video/"; //String inpath="/Volumes/Reservoir/Assets/Video"; //String fname="abby gas station"; //String fname="MOV09976.MPG"; String fname="abby at computer.mov"; String outpath="/Volumes/extra/Faces/"+fname+"_"+DETECTION_CASCADE; // ---- database for face information ---- // MySQL msql; String user="bob"; String pass="password"; String database="looking"; String table="faces"; int video_id=-1; void setup() { //size(1280, 720, P2D); // size(screen.width, screen.height); size(1920, 1080, P3D); background(0); strokeWeight(2); noFill(); // Font and text drawing setup font = loadFont("HelveticaNeue-48.vlw"); textAlign(LEFT); // textAlign(CENTER,CENTER); rectMode(CORNER); fill(255); textFont(font, 24); myMovie = new GSMovie(this, savePath(inpath+"/"+fname)); myMovie.play(); agents = new Gaggle(this, myMovie.width, myMovie.height ); last=-1000; // connect do db for face-tracking msql = new MySQL( this, "localhost", database, user, pass ); if ( !msql.connect() ) { // connection failed ! println("connection failed!"); exit(); } // check if file exists in database video_id=-1; msql.query("SELECT * FROM media WHERE fname=\""+fname+"\""); while (msql.next()) { video_id=msql.getInt("id"); println(" video already in media table as video_id "+video_id); } if(video_id==-1) { // add video file to media table msql.execute("INSERT INTO media (name, fname, path, filetype, extension) VALUES (\""+ fname+"\", \""+fname+"\", \""+inpath+"\", \"video\", \"\")"); // check if file exists msql.query("SELECT * FROM media WHERE fname=\""+fname+"\""); while(msql.next()) { video_id=msql.getInt("id"); println(" video inserted into media table as video_id "+video_id); } } println(DETECTION_CASCADE); } void doFaceTracking() { frame++; myMovie.loadPixels(); frameimg = new PImage(myMovie.width, myMovie.height, RGB); arraycopy(myMovie.pixels, frameimg.pixels); frameimg.updatePixels(); int count = agents.checkframe(frameimg); if(count>0) { println("frame: "+str(myMovie.frame())+", "+count+" faces"); } else { println(" no faces in frame."); } } void movieEvent(Movie myMovie) { myMovie.read(); } void draw() { if((!paused)) { if (newFrame != myMovie.frame()) { // The movie stream must be in play mode in order to jump to another // position along the stream. Otherwise it won't work. myMovie.play(); myMovie.jump(newFrame); myMovie.pause(); } println(newFrame+" "+myMovie.frame()); background(0); image(myMovie, 0, 0, 1920, 1080); fill(64, 64, 64); text(myMovie.time()+" s\n"+myMovie.frame()+"\n"+myMovie.length()+" frames\n"+DETECTION_CASCADE, 50, myMovie.height+50); int linepos=round(map(myMovie.frame(), 0, myMovie.length(), 0, width)); stroke(128); line(linepos, height-50, linepos, height); noFill(); doFaceTracking(); agents.relax(); } } void saveSnapShot() { //myMovie.save(savePath("/Users/rtwomey/Desktop/images/"+vidName)); save("snapshot_"+str(myMovie.time())); } void mousePressed() { int fnum=round(float(mouseX)/float(width)*myMovie.length()); println("jumping to frame "+fnum+" of "+myMovie.length()); myMovie.jump(fnum); } public void stop() { agents.stop(); super.stop(); } void keyPressed() { if(key==' ') paused = (paused == true) ? false : true; if(key=='s') saveSnapShot(); if (key == CODED) { if (keyCode == LEFT) { if (0 < newFrame) newFrame--; } else if (keyCode == RIGHT) { if (newFrame < myMovie.length() - 1) newFrame++; } } }