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; PVector maxpoint; 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]; maxpoint = new PVector(0, 0, 0); calcDiffImage(); } void draw() { //createStrokeGroup(); //searchInRectangle(biggest.x, biggest.y, biggest.width, biggest.height); calcDiffImage(); drawStroke(); } void drawStroke() { float x, y, len; x=maxpoint.x; y=maxpoint.y; stroke(0.0, 128); strokeWeight(random(2,5)); len=random(30); line(x, y, x+random(len), y+random(len)); } 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(brightmaxval) { maxval=brightness(temp.get(i, j)); maxpoint.x=(float)i; maxpoint.y=(float)j; } // // working with blobs // Blob[] blobs = opencv.blobs( 100, (int)(imgw*imgh*0.25), 5, true ); // // noFill(); // // pushMatrix(); // translate(imgw, 480); // scale(0.4); // fill(255); // rect(0, 0, imgw, imgh); // boolean found=false;; // for ( int i=0; i0 ) { // beginShape(); // for ( int j=0; j