/** * * 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.*; //Movie myMovie; SteppedMovie 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=67423; float moviepos=519.8; 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 currvideo=0; 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(1280, 720, P2D); size(screen.width, screen.height-50); 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); connectToDb(); retrieveVideoIDs(); currvideo=100; // start at movie nextMovie(); agents = new Gaggle(this, myMovie.width, myMovie.height ); last=-1000; println(DETECTION_CASCADE); } void connectToDb() { // connect do db for face-tracking msql = new MySQL( this, "localhost", database, user, pass); if ( !msql.connect() ) { // connection failed ! println("connection failed!"); System.exit(-1); } } void retrieveVideoIDs() { videoIDs = new ArrayList(); // msql.query("SELECT DISTINCT(id) FROM media WHERE path=\"/Volumes/Reservoir/Assets/Video\""); msql.query("SELECT DISTINCT(id), fname FROM media WHERE filetype=\"video\" ORDER BY id"); while(msql.next()) { String fname=msql.getString("fname"); video_id=msql.getInt("id"); videoIDs.add(video_id); println(videoIDs.size()+" "+video_id+" "+fname); } if(videoIDs.size()<=0) { println("no video files found in DB. exiting."); System.exit(-1); } else { println((videoIDs.size()-1)+" video files"); } } boolean loadMovie() { video_id=(Integer)videoIDs.get(currvideo); if(msql.connect()==false) { connectToDb(); } msql.query("SELECT * FROM media WHERE id="+video_id); msql.next(); file_name = msql.getString("fname"); fname=file_name; String path=msql.getString("path"); println("opening "+currvideo+" of "+videoIDs.size()+". id "+video_id+" "+path+"/"+file_name+"."); // open movie file try { myMovie = new SteppedMovie(this, savePath(path+"/"+file_name)); if(myMovie!=null) { myMovie.precalcFrameTimes(); myMovie.read(); println(" file is "+myMovie.getFrameCount()+" frames long."); //if(myMovie.getFrameCount()<=1) return -1; return true; } else { return false; } } catch (Throwable t) { println(" "+t); return true; } } void nextMovie() { currvideo++; if(currvideo>=videoIDs.size()) currvideo=0; while(loadMovie()==false) { currvideo++; if(currvideo>=videoIDs.size()) currvideo=0; } outpath="/Volumes/extra/Faces/"+file_name; } 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.getCurrentFrameNumber())+", "+count+" faces"); } else { //println(" no faces in frame."); } } void draw() { if((!paused)) { // erase image and put curr video frame if(myMovie.done()) { nextMovie(); } else { myMovie.read(); myMovie.stepForward(); background(0); try { image(myMovie, 0, 0, myMovie.width, myMovie.height); } catch (Throwable t) { }; fill(64, 64, 64); text(myMovie.time()+" s\n"+myMovie.getCurrentFrameNumber()+" of "+myMovie.getFrameCount()+" frames\n"+currvideo+" of "+videoIDs.size()+". "+video_id+" "+file_name+"\n"+DETECTION_CASCADE, 50, myMovie.height+50); int linepos=round(map(myMovie.getCurrentFrameNumber(), 0, myMovie.getFrameCount(), 0, width)); stroke(128); line(linepos, height-50, linepos, height); noFill(); doFaceTracking(); newframe=false; } agents.relax(); } } void mousePressed() { int fnum=round(float(mouseX)/float(width)*myMovie.getFrameCount()); println("jumping to frame "+fnum); myMovie.gotoFrameNumber(fnum); } void keyPressed() { if(key==' ') paused = !paused; if(keyCode==RIGHT) nextMovie(); } public void stop() { agents.stop(); super.stop(); }