/** * * 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=0; int facenum=0; int frame=0; int id=0; int startframe=0; float moviepos=0; float lasttime=0; boolean newframe=false; // ---- 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/tera 4/Assets/Video"; String inpath="/Volumes/Reservoir/Assets/Video"; //String fname="abby gas station"; ArrayList videoIDs; int j=404; String file_name, fname; String outpath="/Users/rtwomey/Desktop/"; // ---- 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(1920, 1080, P3D); // size(screen.width, screen.height); 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); // connect do db for face-tracking msql = new MySQL( this, "localhost", database, user, pass ); if ( !msql.connect() ) { // connection failed ! println("connection failed!"); exit(); } retrieveVideoIDs(); nextMovie(); agents = new Gaggle(this, myMovie.width, myMovie.height ); last=-1000; println(DETECTION_CASCADE); delay(5000); } void retrieveVideoIDs() { // query faces table for faces with width > 100 videoIDs = new ArrayList(); msql.query("SELECT DISTINCT(id) FROM media WHERE filetype=\"video\" ORDER BY id"); while(msql.next()) { video_id=msql.getInt("id"); videoIDs.add(video_id); println(video_id); } println(videoIDs.size()+" video files"); if(videoIDs.size()<=0) exit(); } void loadMovie() { frame=0; video_id=(Integer)videoIDs.get(j); msql.query("SELECT * FROM media WHERE id="+video_id); while(msql.next()) { file_name = msql.getString("fname"); fname=file_name; String path=msql.getString("path"); print(" opening video "+j+" id "+video_id+" "+path+"/"+file_name+". "); // open movie file // if(myMovie!=null)myMovie.delete(); myMovie = new GSMovie(this, savePath(path+"/"+file_name)); myMovie.play(); } delay(1000); } void nextMovie() { j++; if(j>=videoIDs.size())j=0; loadMovie(); } 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(GSMovie myMovie) { myMovie.read(); } void nextFrame() { int lastframe=myMovie.frame(); int count=0; if(frame!=myMovie.frame()) { myMovie.play(); myMovie.jump(frame); myMovie.pause(); } if(count>200) nextMovie(); } void draw() { if((!paused)) { // erase image and put curr video frame if (frame != 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(frame); myMovie.pause(); } if(myMovie.frame() >= myMovie.length() - 1) { nextMovie(); } else { doFaceTracking(); } agents.relax(); } background(0); // image(myMovie, 0, 0); if(frameimg!=null)image(frameimg, 0, 0); fill(64, 64, 64); text(myMovie.time()+" s\n"+myMovie.frame()+" of "+myMovie.length()+"\n"+file_name+" ("+j+" of "+videoIDs.size()+")\n"+DETECTION_CASCADE, 50, 50); int linepos=round(map(myMovie.frame(), 0, myMovie.length(), 0, width)); stroke(128); line(linepos, height-50, linepos, height); noFill(); } 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); myMovie.jump(fnum); } void keyPressed() { if(key==' ') paused = (paused == true) ? false : true; if(key=='s') saveSnapShot(); if(keyCode==RIGHT) { nextMovie(); } } public void stop() { myMovie.delete(); agents.stop(); super.stop(); }