Hello, I am using the BlobDetection library and want to use the outlines created by the edge detection to form shapes so that I can fill in the shapes. So far the solution I have come up with is to draw lines coming from the pixels that create the contour. However, the lines go all the way to the bottom so if you raise your arm for example, the line will not stop at the bottom of your arm where the contour is but continue to the bottom of the screen. So I am looking for a way to fill the contours with color, and ideally at the end I will remove the contour line to be left with just a shadow.
(sorry if the solutions I came up with are rudimentary, quite new at javascript!) (Please note - the image will appear at its best when you are in front of a white background in a well-lit space. To change lighting thresholds to adjust, go to line #31 " theBlobDetection.setThreshold(.6f); // will detect bright areas whose luminosity > 0.2f;" )
here is my code so far:
import processing.video.*; import blobDetection.*; color black = color(200, 255, 250); Capture cam; BlobDetection theBlobDetection; PImage img; boolean newFrame=false;
void setup() {
fullScreen(); cam = new Capture(this, 404, 304, 15); cam.start();
img = new PImage(300, 60); theBlobDetection = new BlobDetection(img.width, img.height); theBlobDetection.setPosDiscrimination(true); theBlobDetection.setThreshold(.6f); // will detect bright areas whose luminosity > 0.2f; }
void captureEvent(Capture cam) { cam.read(); newFrame = true; }
void draw() {
{
if (newFrame) {
{
background(50);
newFrame=true;
img.copy(cam, 0, 0, cam.width, cam.height,
0, 0, img.width, img.height);
for (int i = 0; i < 200000; i++) {
float x = random(width);
float y = random(height);
fill(255, 255, 255);
text(".", x, y);
frameRate(100);
}
if (frameCount % 10 == 0) println(frameRate);
fastblur(img, 2);
theBlobDetection.computeBlobs(img.pixels);
drawBlobsAndEdges(true, true);
}
}
} } void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges) { Blob b; EdgeVertex eA, eB; for (int n=0; n<theBlobDetection.getBlobNb(); n++) { b=theBlobDetection.getBlob(n); if (b!=null) {
if (drawEdges)
{
for (int m=0; m<b.getEdgeNb(); m++)
{
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null) {
// inner lines
stroke(255, 0, 0);
strokeWeight(2);
smooth();
line(eA.x*width-10, eA.y*height-10,
eB.x*width-10, eB.y*height-10
);
stroke (0);
strokeWeight(14);
smooth();
line(eA.x*width, eA.y*height,
eB.x*width, eB.y*height
);
}
strokeWeight(10);
strokeCap(ROUND);
stroke(0);
line(eA.x*width, eB.y*height+10, eA.x*width, eB.y*height - -height);
}
}
}
if (drawBlobs)
{
strokeWeight(10);
stroke(255);
}
} }
// ================================================== // Super Fast Blur v1.1 // by Mario Klingemann // http://incubator.quasimondo.com // ================================================== 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=wh; 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[256div]; for (i=0; i<256*div; i++) { dv[i]=(i/div); }
yw=yi=0;
for (y=0; y<h; y++) { rsum=gsum=bsum=0; for (i=-radius; i<=radius; i++) { p=pix[yi+min(wm, max(i, 0))]; rsum+=(p & 0xff0000)>>16; gsum+=(p & 0x00ff00)>>8; bsum+= p & 0x0000ff; } for (x=0; x<w; x++) {
r[yi]=dv[rsum];
g[yi]=dv[gsum];
b[yi]=dv[bsum];
if (y==0) {
vmin[x]=min(x+radius+1, wm);
vmax[x]=max(x-radius, 0);
}
p1=pix[yw+vmin[x]];
p2=pix[yw+vmax[x]];
rsum+=((p1 & 0xff0000)-(p2 & 0xff0000))>>16;
gsum+=((p1 & 0x00ff00)-(p2 & 0x00ff00))>>8;
bsum+= (p1 & 0x0000ff)-(p2 & 0x0000ff);
yi++;
}
yw+=w;
}
for (x=0; x<w; x++) { rsum=gsum=bsum=0; yp=-radiusw; for (i=-radius; i<=radius; i++) { yi=max(0, yp)+x; rsum+=r[yi]; gsum+=g[yi]; bsum+=b[yi]; yp+=w; } yi=x; for (y=0; y<h; y++) { pix[yi]=0xff000000 | (dv[rsum]<<16) | (dv[gsum]<<8) | dv[bsum]; if (x==0) { vmin[y]=min(y+radius+1, hm)w; vmax[y]=max(y-radius, 0)*w; } p1=x+vmin[y]; p2=x+vmax[y];
rsum+=r[p1]-r[p2];
gsum+=g[p1]-g[p2];
bsum+=b[p1]-b[p2];
yi+=w;
}
} }