class Blobs { //Capture cam; BlobDetection theBlobDetection; PImage img; boolean newFrame=false; // ================================================== // setup() // ================================================== Blobs() { // Size of applet //size(640, 480); // Capture // cam = new Capture(this, 40*1, 30*1, 15); // parent, width, height, fps // BlobDetection // img which will be sent to detection (a smaller copy of the cam frame); img = new PImage(40,30); theBlobDetection = new BlobDetection(img.width, img.height); theBlobDetection.setPosDiscrimination(true); // look for light or dark areas ?? // IMPORTANT TO KEEP THE THRESHOLD LOW : not detect v.bright areas : 0.05 seems to work theBlobDetection.setThreshold(0.05f); // will detect bright areas whose luminosity > 0.2f; } // ================================================== // captureEvent() // ================================================== // void captureEvent(Capture cam) { // cam.read(); // newFrame = true; // } // ================================================== // draw() // ================================================== void goBlobs() { //if (newFrame) { //background (255); // newFrame=false; //image(cam,0,0,width,height); // draw camera to stage img.copy(cam, 0, 0, cam.width, cam.height, 0, 0, img.width, img.height); fastblur(img, 2); // blur the image // smooths blobs ?? theBlobDetection.computeBlobs(img.pixels); drawBlobsAndEdges(true, true); // } } // ================================================== // drawBlobsAndEdges() // ================================================== void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges) { noFill(); Blob b; EdgeVertex eA,eB; /// getBlobNb == get number of blobs for (int n=0 ; n // ================================================== void fastblur(PImage img,int radius) { if (radius<1){ return; } int w=img.width; int h=img.height; int wm=w-1; int hm=h-1; int wh=w*h; int div=radius+radius+1; int r[]=new int[wh]; int g[]=new int[wh]; int b[]=new int[wh]; int rsum,gsum,bsum,x,y,i,p,p1,p2,yp,yi,yw; int vmin[] = new int[max(w,h)]; int vmax[] = new int[max(w,h)]; int[] pix=img.pixels; int dv[]=new int[256*div]; for (i=0;i<256*div;i++){ dv[i]=(i/div); } yw=yi=0; for (y=0;y>16; gsum+=(p & 0x00ff00)>>8; bsum+= p & 0x0000ff; } for (x=0;x>16; gsum+=((p1 & 0x00ff00)-(p2 & 0x00ff00))>>8; bsum+= (p1 & 0x0000ff)-(p2 & 0x0000ff); yi++; } yw+=w; } for (x=0;x