We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I have used Blobscanner library for blob recognition. This library works fine and don't have any problem with it but here I have the issue with using it properly. Actually, what I am trying to do is to get the blob of drawn stroke. I have used two PGraphics layer, one for drawing blob and other for canvas drawing. Problems are when ever I tried to draw with random color it doesn't recognize the blob for every color. Also programs gets slow if so many blob gets detected. Third problem is drawing centroid and getting the pixel color at centroid. It shows very different values like I shown in the picture below
import Blobscanner.*;
PGraphics edges;
PGraphics testLayer;
Detector bs;
int minimumWeight = 900;
final int MAXEDGES = (320*240)/4;
int[] X ;
int[] Y ;
color c;
void setup() {
size(500, 500);
bs = new Detector(this, 0, 0, width, height, 255);
edges = createGraphics(width, height);
testLayer = createGraphics(width, height);
testLayer.beginDraw();
testLayer.endDraw();
}
void draw() {
background(255);
if (keyPressed) {
c = color(random(0, 255), random(0, 255), random(0, 255));
}
//---------------------------------
testLayer.beginDraw();
if (mousePressed) {
// testLayer.fill(c);
// testLayer.noStroke();
testLayer.stroke(c);
testLayer.strokeWeight(20);
testLayer.line(mouseX, mouseY, pmouseX, pmouseY);
//testLayer.ellipse(mouseX, mouseY, 30, 30);
}
testLayer.endDraw();
//---------------------------------
int k = 0;
bs.imageFindBlobs(testLayer);
bs.loadBlobsFeatures();
bs.weightBlobs(false);
bs.findCentroids(false, false);
getEdgeCoordinates();
edges.beginDraw();
for (int i = 0; boolean( X[i]); i++) {
edges.stroke(0, 255, 0);
edges.strokeWeight(3);
edges.point(X[i], Y[i]);//or do what you want
}
//--------------------------------------------------
bs.findCentroids(false, false);
for (int i = 0; i < bs.getBlobsNumber(); i++) {
edges.point(bs.getCentroidX(i), bs.getCentroidY(i));
color c = testLayer.get((int)bs.getCentroidX(i), (int)bs.getCentroidY(i));
float r = red(c);
float g = green(c);
float b = blue(c);
println("r: " + r + " g: " + g + " b: " + b);
}
//--------------------------------------------------
edges.endDraw();
image(testLayer, 0, 0);
image(edges, 0, 0);
}
void getEdgeCoordinates() {
X = new int[MAXEDGES];
Y = new int[MAXEDGES];
int i = 0;
for (int y = 0; y < testLayer.height; y++) {
for (int x = 0; x < testLayer.width; x++) {
if (bs.isEdge(x, y) &&
bs.getBlobWeightLabel(bs.getLabel(x, y)) >= minimumWeight) {
X[i] = x;
Y[i] = y;
i++;
}
}
}
}
Answers
For those who want Answer ....