class Agent { // for data smoothing int SAMPLES = 20; int PERSISTENCE=10; int curr; int id; int lastseen; boolean avgcalcd; boolean finishflag; int[] sx = new int[SAMPLES]; int[] sy = new int[SAMPLES]; int[] sw = new int[SAMPLES]; int[] sh = new int[SAMPLES]; float ax, ay, aw, ah; Agent(int i, int x, int y, int w, int h) { fillAvg(x, y, w, h); id=i; curr=0; lastseen=PERSISTENCE; avgcalcd=false; finishflag=false; } void fillAvg(int x, int y, int w, int h) { for(int i=0;i=SAMPLES)curr=0; sx[curr]=x; sy[curr]=y; sw[curr]=w; sh[curr]=h; calcAvg(); lastseen=PERSISTENCE; } void drawAvg(int i) { if(!avgcalcd) calcAvg(); stroke(0, 0, 255); rect( ax, ay, aw, ah); PImage face = frameimg.get(max(round(ax),0), max(0, round(ay)), round(aw), round(ah)); image(face, 750+225*(i/5), 225*(i%5), 200, 200); face.save(savePath(outpath+"/"+fname+"_"+id+"_"+str(myMovie.getCurrentFrameNumber()))); fill(64, 64, 64); text(myMovie.time(), 800, 375); noFill(); } void addToDB(int i) { if(!avgcalcd) calcAvg(); stroke(0, 0, 255); rect( ax, ay, aw, ah); PImage face = frameimg.get(max(round(ax),0), max(0, round(ay)), max(0, round(aw)), max(0, round(ah))); image(face, 750+225*(i/5), 225*(i%5), 200, 200); // face.save(savePath(outpath+"/"+fname+"_"+id+"_"+str(myMovie.getCurrentFrameNumber()))); msql.execute("INSERT INTO "+table+" (video_id, frame_num, face_id, x_pos, y_pos, width, height, classifier) VALUES ("+ video_id+", "+str(myMovie.getCurrentFrameNumber())+", "+id+", "+ax+", "+ay+", "+aw+", "+ah+", \""+DETECTION_CASCADE+"\")"); fill(64, 64, 64); text(myMovie.time(), 800, 375); noFill(); } void drawAvg() { drawAvg(0); } void relax() { lastseen--; if(lastseen<=0) finishflag=true; } boolean isFinished() { return finishflag; } float distance(int testx, int testy, int testw, int testh) { if(!avgcalcd) calcAvg(); float tmp=dist(ax, ay, testx, testy); return tmp; } }