Monday, 6 December 2010

[Development] Blob Test with Processing









Processing



[blob test]















original open codes: BlobDetection by v3ga.net





//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

//BlobDetection by v3ga

//May 2005

//Processing(Beta) v0.85

//

// Adding edge lines on the image process in order to 'close' blobs

//

// ~~~~~~~~~~

// software :

// ~~~~~~~~~~

// - Super Fast Blur v1.1 by Mario Klingemann

// - BlobDetection library

//

// ~~~~~~~~~~

// hardware :

// ~~~~~~~~~~

// - Sony Eye Toy (Logitech)

//

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



import processing.video.*;

import blobDetection.*;



Capture cam;

BlobDetection theBlobDetection;

PImage img;

boolean newFrame=false;



// ==================================================

// setup()

// ==================================================

void setup()

{

// Size of applet

size(640, 480);

// Capture

cam = new Capture(this, 40*4, 30*4, 15);

// BlobDetection

// img which will be sent to detection (a smaller copy of the cam frame);

img = new PImage(80,60);

theBlobDetection = new BlobDetection(img.width, img.height);

theBlobDetection.setPosDiscrimination(true);

theBlobDetection.setThreshold(0.2f); // will detect bright areas whose luminosity > 0.2f;

}



// ==================================================

// captureEvent()

// ==================================================

void captureEvent(Capture cam)

{

cam.read();

newFrame = true;

}



// ==================================================

// draw()

// ==================================================

void draw()

{

if (newFrame)

{

newFrame=false;

image(cam,0,0,width,height);

img.copy(cam, 0, 0, cam.width, cam.height,

0, 0, img.width, img.height);

fastblur(img, 2);

theBlobDetection.computeBlobs(img.pixels);

drawBlobsAndEdges(true,true);

}

}



// ==================================================

// drawBlobsAndEdges()

// ==================================================

void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges)

{

noFill();

Blob b;

EdgeVertex eA,eB;

for (int n=0 ; n

// ==================================================

void fastblur(PImage img,int radius)

{

if (radius<1){ w="img.width;" h="img.height;" wm="w-1;" hm="h-1;" wh="w*h;" div="radius+radius+1;" pix="img.pixels;" i="0;i<256*div;i++){" yw="yi=" 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<<16) x="=" p1="x+vmin[y];" p2="x+vmax[y];" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtz9wTx8BHrL9_wAVawQ7-z7AFAqPhAScEY4E23KMJkGxul2b36544kR2Sb47yylz3y7xX1oP3IJg0nbDFApgPgI5kJFz25wbhEVLXDXb20Xv1PqWveAUAekhOVAWdW5VzXczPJOEAtGxA/s1600/bd_webcam.JPG">Yoon: I just copied the codes and pasted into a new sketch. But the original itself is a bit too rough to be used as it is. First of all, my room isn't as bright as I expected that there may be some interference from ambient lights. Secondly, the output image is pixelated which may not give clear border to judge blob areas. Thirdly, the red rectangulars are not necessary and the colour of edge (light green) is not suitable. So I added some codes from another open source which to make the quality of image better, removed red straight lines and tested changing the colour of edges.





Fixed codes:



//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

//BlobDetection by v3ga

//May 2005

//Processing(Beta) v0.85

//

// Adding edge lines on the image process in order to 'close' blobs

//

// ~~~~~~~~~~

// software :

// ~~~~~~~~~~

// - Super Fast Blur v1.1 by Mario Klingemann

// - BlobDetection library

//

// ~~~~~~~~~~

// hardware :

// ~~~~~~~~~~

// - Sony Eye Toy (Logitech)

//

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



import processing.video.*;

import blobDetection.*;



Capture cam;

BlobDetection theBlobDetection;

PImage img;

boolean newFrame=false;



// ==================================================

// setup()

// ==================================================

void setup()

{

// Size of applet

size(640, 480);

// Capture

cam = new Capture(this, width, height, 30); noStroke(); smooth();

// BlobDetection

// img which will be sent to detection (a smaller copy of the cam frame);

img = new PImage(80,60);

theBlobDetection = new BlobDetection(img.width, img.height);

theBlobDetection.setPosDiscrimination(true);

theBlobDetection.setThreshold(0.2f); // will detect bright areas whose luminosity > 0.2f;

}



// ==================================================

// captureEvent()

// ==================================================

void captureEvent(Capture cam)

{

cam.read();

newFrame = true;

}



// ==================================================

// draw()

// ==================================================

void draw()

{

if (newFrame)

{

newFrame=false;

image(cam,0,0,width,height);

img.copy(cam, 0, 0, cam.width, cam.height,

0, 0, img.width, img.height);

fastblur(img, 2);

theBlobDetection.computeBlobs(img.pixels);

drawBlobsAndEdges(false,true);

}

}



// ==================================================

// drawBlobsAndEdges()

// ==================================================

void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges)

{

fill(0,0,0);

Blob b;

EdgeVertex eA,eB;

for (int n=0 ; n5);

stroke(174,25,36);

for (int m=0;m

// ==================================================

void fastblur(PImage img,int radius)

{

if (radius<1){ w="img.width;" h="img.height;" wm="w-1;" hm="h-1;" wh="w*h;" div="radius+radius+1;" pix="img.pixels;" i="0;i<256*div;i++){" yw="yi=" 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

rsum=gsum=bsum=0;

yp=-radius*w;

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

pix[yi]=0xff000000 | (dv[rsum]<<16) x="=" p1="x+vmin[y];" p2="x+vmax[y];">


Yoon: the webcam caught the completely dark area. And then I did simular but with my mobile device and it was to compare to a dark point in brighter background.







Yoon: The webcam seems trying to catch some pitch-black area first and comparatively adjusts rest of area with ambient light.

No comments:

Post a Comment