We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, A question from one of the Processing examples for blob detection. Here is the code:
import blobDetection.*;
BlobDetection theBlobDetection;
PGraphics img;
// ==================================================
// setup()
// ==================================================
void setup()
{
// Works with Processing 1.5
// img = createGraphics(640, 480,P2D);
// Works with Processing 2.0b3
img = createGraphics(640, 480);
img.beginDraw();
img.background(255);
img.noStroke();
img.fill(0);
for (int i=0;i<20;i++) {
float r = random(50);
img.ellipse(random(img.width), random(img.height), r, r);
}
img.endDraw();
theBlobDetection = new BlobDetection(img.width, img.height);
theBlobDetection.setPosDiscrimination(false);
theBlobDetection.setThreshold(0.38f);
theBlobDetection.computeBlobs(img.pixels);
// Size of applet
size(img.width, img.height);
}
// ==================================================
// draw()
// ==================================================
void draw()
{
image(img, 0, 0, width, height);
drawBlobsAndEdges(true, true);
}
// ==================================================
// drawBlobsAndEdges()
// ==================================================
void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges)
{
noFill();
Blob b;
EdgeVertex eA, eB;
for (int n=0 ; n<theBlobDetection.getBlobNb() ; n++)
{
b=theBlobDetection.getBlob(n);
if (b!=null)
{
// Edges
if (drawEdges)
{
strokeWeight(2);
stroke(0, 255, 0);
for (int m=0;m<b.getEdgeNb();m++)
{
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)
line(
eA.x*width, eA.y*height,
eB.x*width, eB.y*height
);
}
}
// Blobs
if (drawBlobs)
{
strokeWeight(1);
stroke(255, 0, 0);
rect(
b.xMin*width, b.yMin*height,
b.w*width, b.h*height
);
}
}
}
}
How can I do blob detection for just half an image?? Thanks
Answers
Perhaps you can get() this half, and use the resulting PImage in the blob init?
Okay thanks. But any ideas on how to read half a webcam capture and pass it to blob detection?
This is what I have done so far, but the results aren't what I expected. Changes were made in the draw() section.
"any ideas on how to read half a webcam capture and pass it to blob detection?"
That's what I meant with my reference (obscure, perhaps), to get().