Hi rodanet,
Thanks for your quick reply.
I've had a go at trying out the code you've suggested and I've encountered a couple of problems.
First the overall performance when using video capture is somehow slow. It seems to work fine if its 320 wide, but if I try to use 640*480 it takes ages to draw the image to screen and when it does that framerate is very slow. I don't know if this is due to the fact I'm working in a mac, but I was using these dimensions with opencv and the performance was fine.
In relation to the isBlob() method, it doesn't seem to like PImages. So if I do:
if(bd.isBlob(x, y)){
blobImage.pixels[loc] = video.pixels[loc];
} else {
bgImage.pixels[loc] = color(0);
}
nothing happens, but if I do:
if(bd.isBlob(x, y)){
blobImage.pixels[loc] = video.pixels[loc];
} else {
set(x,y, color(0));
}
It does make the pixels that are not blobs black.
Also when I set weighBlobs to true, it prints out that no blobs have been found, but it actually recognizes that there're blobs and draws the contourns and boxes around them. I don't know, it's strange!
Do you have any suggestions on how to be able to store the blob information in a PImage? Maybe I'm making a silly mistake.
I've included my code below.
Thanks!!!
- import processing.video.*;
import Blobscanner.*;
Capture video;
Detector bd;
int w = 320;
int h = 240;
float thres =0.5;
PImage blobImage;
PImage bgImage;
void setup(){
size(w, h);
video = new Capture(this, w, h, 30);
bd = new Detector( this, 0, 0, video.width, video.height, 255);
blobImage = createImage(video.width,video.height,ARGB);
bgImage = createImage(video.width,video.height,ARGB);
}
void draw(){
if(video.available()) {
video.read();
}
image(video, 0, 0);
video.loadPixels();
bgImage.loadPixels();
blobImage.loadPixels();
video.filter(THRESHOLD, thres);
bd.findBlobs(video.pixels, video.width, video.height);
//This call is indispensable for nearly all the other methods
//(please check javadoc).
bd.loadBlobsFeatures();
//This methods needs to be called before to call
//findCentroids(booleaan, boolean) methods.
bd.weightBlobs(true);
//Computes the blob center of mass. If the first argument is true,
//prints the center of mass coordinates x y to the console. If the
//second argument is true, draws a point at the center of mass coordinates.
bd.findCentroids(false, false);
// draw box around blob (color, thickness of the box)
bd.drawBox(color(255, 0, 0), 1);
bd.drawContours(color(255, 0, 0), 1);
for(int x = 0; x < video.width; x++){
for(int y = 0; y < video.height; y++){
int loc = x+y*video.width;
if(bd.isBlob(x, y)){
blobImage.pixels[loc] = video.pixels[loc]; - //set(x,y, color(0));
} else {
set(x,y, color(0));
//bgImage.pixels[loc] = color(0);
}
}
}
}
void mouseDragged() {
thres = map(mouseX,0, width, 0, 1);
}