import hypermedia.video.*; import java.awt.*; OpenCV opencv; import controlP5.*; PImage img; ControlP5 controlP5; static float imgw = 800; static float imgh = 600; PImage diffImg; PImage current; static int MAXPOINTS = 10; PVector [] mypoints; float center=64.0; float width=64.0; float thresh=16.0; int count=0; Rectangle biggest; void setup() { size(1600, 800); opencv = new OpenCV( this ); img = loadImage("urs_firscher_060_push.jpg"); // Load demo image opencv.loadImage("urs_firscher_060_push.jpg", (int)imgw, (int)imgh); opencv.convert( OpenCV.GRAY ); // convert to gray background(255); controlP5 = new ControlP5(this); controlP5.addSlider("center") .setPosition(imgw-160, imgh+20) .setRange(0, 255) .setValue(center) .setCaptionLabel("center"); controlP5.addSlider("width") .setPosition(imgw-160, imgh+40) .setRange(0, 255) .setValue(width) .setCaptionLabel("width"); controlP5.addSlider("thresh") .setPosition(imgw-160, imgh+60) .setRange(0, 255) .setValue(thresh) .setCaptionLabel("thresh"); mypoints = new PVector[MAXPOINTS]; calcDiffImage(); } void draw() { //createStrokeGroup(); searchInRectangle(biggest.x, biggest.y, biggest.width, biggest.height); drawStrokeGroup(); //noFill(); //rect(biggest.x, biggest.y, biggest.width, biggest.height); count++; if (count==10) { calcDiffImage(); count=0; } } PVector findPoint() { return findPoint(0, 255); }; PVector findPoint(float center, float width) { color c; float ix, iy; float x, y; float bright; boolean done=false; // weighted sample towards darker pixels do { ix=random(0, img.width); iy=random(0, img.height); c = img.get((int)ix, (int)iy); bright = brightness(c); if ((bright>center-width/2) && (bright<=center+width/2)) done=true; } while ( !done); //println(ix); //println(iy); return new PVector(ix, iy); } PVector findPoint(float center, float width, float x, float y, float w, float h) { color c; float ix, iy; float bright; boolean done=false; do { ix=x+random(w); iy=y+random(h); //c = img.get((int)ix, (int)iy); // bright = brightness(c); //if ((bright>center-width/2) && (bright<=center+width/2) && (random (width)<(float)width/2)) done=true; //if(bright0 ) { beginShape(); for ( int j=0; j