@@ -0,0 +1,2058 @@
+package com.haxademic.core.draw.image;%0A%0Aimport com.haxademic.core.app.P;%0Aimport com.haxademic.core.draw.filters.pshader.EdgeColorDarkenFilter;%0A%0Aimport blobDetection.BlobDetection;%0Aimport processing.core.PGraphics;%0A%0Apublic class BlobFinder %7B%0A%09%0A%09protected BlobDetection blobDetection;%0A%09protected PGraphics sourceBuffer;%0A%09protected PGraphics blobSourceBuffer;%0A%09protected PGraphics blobOutputBuffer;%0A%0A%0A%09protected BlobFinder(PGraphics sourceBuffer, float scale) %7B%0A%09%09// store source buffer%0A%09%09this.sourceBuffer = sourceBuffer;%0A%09%09%0A%09%09// create scaled-down offscreen buffer for blob processing%0A%09%09int blurImgW = P.round(sourceBuffer.width * scale);%0A%09%09int blurImgH = P.round(sourceBuffer.height * scale);%0A%09%09blobSourceBuffer = P.p.createGraphics(blurImgW, blurImgH, P.P2D);%0A%09%09blobOutputBuffer = P.p.createGraphics(blurImgW, blurImgH, P.P2D);%0A%0A%09%09%0A//%09%09// set up blur shader for blob pre-processing%0A//%09%09float shaderBlurAmount = 1f;%0A//%09%09BlurHFilter.instance(P.p).setBlurByPercent(shaderBlurAmount, blurImgW);%0A//%09%09BlurVFilter.instance(P.p).setBlurByPercent(shaderBlurAmount, blurImgH);%0A%0A%09%09// init blob detection object%0A%09%09blobDetection = new BlobDetection(blurImgW, blurImgH);%0A%09%09blobDetection.setPosDiscrimination(true);%09// true if looking for bright areas%0A%09%09blobDetection.setThreshold(0.5f); // will detect bright areas whose luminosity %3E threshold%0A%09%7D%0A%09%0A%09public BlobDetection blobDetection() %7B%0A%09%09return blobDetection;%0A%09%7D%0A%09%0A%09public void update() %7B%0A%09%09// copy frame difference buffer%0A%09%09ImageUtil.copyImage(sourceBuffer, blobSourceBuffer);%0A%09%09%0A%09%09// darken the edges to help with blob cleanliness%0A%09%09EdgeColorDarkenFilter.instance(P.p).setSpreadX(0.05f);%0A%09%09EdgeColorDarkenFilter.instance(P.p).setSpreadY(0.05f);%0A%09%09EdgeColorDarkenFilter.instance(P.p).applyTo(blobSourceBuffer);%0A%09%09%0A%09%09// blur for blob computation smoothness%0A//%09%09BlurHFilter.instance(P.p).applyTo(blobSourceBuffer);%0A//%09%09BlurVFilter.instance(P.p).applyTo(blobSourceBuffer);%0A%09%09%0A%09%09// load pixels and pass to blob detection object%0A%09%09blobSourceBuffer.loadPixels();%0A%09%09blobDetection.computeBlobs(blobSourceBuffer.pixels);%0A%09%7D%0A%7D%0A

Add BlobFinder helper class