// Gaggle // Group of Agents class Gaggle { int MAX; // Troop maximum Agent[] population; // Array to hold the current gaggle of agents ArrayList agents; float[] distance; ArrayList darwin; // ArrayList which we will use for our "mating pool" int generations; // Number of generations boolean finished; // Are we finished evolving? OpenCV opencv; int mywidth; int myheight; float THRESHOLD = 70.0; int lastface=0; int count; int nextID; Gaggle(PApplet parent, int in_width, int in_height) { mywidth=in_width; myheight=in_height; opencv = new OpenCV( parent ); opencv.allocate( mywidth, myheight ); // image buffer // opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); opencv.cascade(DETECTION_CASCADE); agents = new ArrayList(); nextID=0; } void checkface(int x, int y, int w, int h) { stroke(255, 0, 0); rect(x, y, w, h); int closest=-1; float distval=MAX_FLOAT; for (int i=0; iTHRESHOLD)) { //println(" adding face, dist = "+str(distval)); nextID++; if(agents.size()<10)agents.add(new Agent(nextID,x, y, w, h)); } else { //println(" updating face "+closest+" with new data "+distval+" pix dist"); ((Agent)agents.get(closest)).update(x, y, w, h); ((Agent)agents.get(closest)).drawAvg(closest); }; } int checkframe(PImage frameimg) { opencv.copy(frameimg, 0, 0, frameimg.width, frameimg.height, 0, 0, myMovie.width, myMovie.height); //image(opencv.image(), 300, 200); // do detection Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 ); int count = faces.length; if (count>0) { //println(" "+count+" faces in frame, currently tracking "+agents.size()+" faces."); for( int i=0; i