import hypermedia.video.*; import java.awt.Rectangle; import de.bezier.data.sql.*; import java.util.Collections; import java.util.Random; OpenCV opencv; // contrast/brightness values int contrast_value = 0; int brightness_value = 0; // face tracking stuff, hold last recognized data int x_pos = 0; int y_pos = 0; int w_face = 0; int h_face = 0; int MAX = 10; int[] x = new int[MAX]; int[] y = new int[MAX]; int[] w = new int[MAX]; int[] h = new int[MAX]; int[][] Faces = new int[MAX][3]; //int[] img = new int[320*240]; PImage img, blackimg; // SQL stuff MySQL msql; PFont font; // what table and what column to query in db // this determines what data is played back String table = "images"; String ftable = "profilefaces"; String column = "name"; PImage input; // vars holding response most recent query String data= ""; String path=""; String fname=""; String filetype=""; // list of table IDs matching query ArrayList imageIDs; Random repeatableRandom; //int i=1900; //int i=2163; //int i=487; int i=477; int facenum=0; int id=0; // timing int last=0; boolean paused=false; void setup() { // general graphics setup //size( 1280, 720 ); size(1100, 1100);//screen.height, screen.height); background(0); smooth(); opencv = new OpenCV( this ); // opencv.capture( width, height ); // open video stream opencv.allocate( width, height ); // image buffer blackimg = createImage(width, height, RGB); blackimg.loadPixels(); for (int i = 0; i < blackimg.pixels.length; i++) { blackimg.pixels[i] = color(0, 0, 0); } // opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml" opencv.cascade(OpenCV.CASCADE_PROFILEFACE); // print usage println( "Drag mouse on X-axis inside this sketch window to change contrast" ); println( "Drag mouse on Y-axis inside this sketch window to change brightness" ); strokeWeight(2); stroke(255,200,0); noFill(); // Font and text drawing setup font = loadFont("HelveticaNeue-48.vlw"); textAlign(CENTER); textAlign(CENTER,CENTER); rectMode(CORNER); fill(255); textFont(font, 64); input = createImage(width-50, height-50, 50); // this example assumes that you are running the // mysql server locally (on "localhost"). // // replace --username--, --password-- with your mysql-account. // String user = "bob"; String pass = "password"; // name of the database to use String database = "naming"; // connect to database of server "localhost" msql = new MySQL( this, "localhost", database, user, pass ); if (msql.connect()) { msql.execute( "CREATE TABLE IF NOT EXISTS " +ftable + " ("+"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, image_id INT (11), filename VARCHAR( 100 ), x_coord VARCHAR(10), y_coord VARCHAR(10), width VARCHAR(10), height VARCHAR(10))"); } else { println("connection failed!"); } msql.query( "SELECT COUNT(*) FROM " + table+" WHERE filetype=\"image\""); msql.next(); println( "number of rows: " + msql.getInt(1) ); imageIDs = new ArrayList(); // build list of image files and shuffle msql.query("SELECT * FROM "+table+" WHERE filetype=\"image\""); while(msql.next()) { data=msql.getString("name"); id=msql.getInt("id"); println(data+" "+id); imageIDs.add(id); } repeatableRandom = new Random(1234); Collections.shuffle(imageIDs, repeatableRandom); last=-1000; } void draw() { if(!paused) { // new query every 1000 ms if(millis()-last>0) { // select image file data from random row msql.query("SELECT * FROM "+table+" WHERE id= "+imageIDs.get(i)); if(msql.next() == true) { i++; if(i>=imageIDs.size()) { exit(); } data = msql.getString("name"); id = msql.getInt("id"); path = msql.getString("path"); fname = msql.getString("fname"); PImage newimage = loadImage(path+"/"+fname); if(newimage!=null) { input=newimage; println("SHOWING: "+i+" "+imageIDs.size()+" "+id+" "+path+"/"+fname); background(0); // image(input, 0, 0, width/2, height/2); // opencv.copy(input.pixels, width, 0, 0, input.width, input.height, 0, 0, width, height); int sw, sh, xoff, yoff; float sf; if(input.width >= input.height) { sf=float(width)/float(input.width); } else { sf=float(height)/float(input.height); } sw=round(input.width*sf); sh=round(input.height*sf); xoff=(width-sw)/2; yoff=(height-sh)/2; //println(" input image: "+input.width+" "+input.height+" "+sf+" "+sw+" "+sh+" "+xoff+" "+yoff); // opencv.copy(input);//, 0, 0, input.width, input.height, xoff, yoff, sw, sh); opencv.copy(blackimg); opencv.copy(input, 0, 0, input.width, input.height, xoff, yoff, sw, sh); // println(" copied to opencv buffer"); opencv.contrast( contrast_value ); opencv.brightness( brightness_value ); // proceed detection Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 ); // display the image // image( opencv.image(), width/2, 0 , width/2, height/2); image( opencv.image(), 0, 0);//, xoff, yoff, sw, sh); // img = opencv.image(); // loadPixels(); // draw face area(s) noFill(); stroke(255,0,0); int count = faces.length; if (count>0) { for( int i=0; i