How to count the blobs that has been detected using theblobdetection library and blobscanner library

edited November 2013 in Library Questions

Hello~ I'm currently trying to do a project which involves counting cars at a traffic junction. I have yet to try it on actual traffic but i'm having trouble just to count the blobs that has been detected. here are samples of my code. Help please

for theblobdetection: i prefer the results using this library

import blobDetection.*;
BlobDetection theBlobDetection;
PImage img;
void setup() 
{

size(640, 480, P2D); 
img = loadImage("cars.jpg");
img.resize(640, 480);
image(img, 0, 0);
theBlobDetection = new BlobDetection(img.width, img.height);
theBlobDetection.setPosDiscrimination(true);
theBlobDetection.setThreshold(0.2f); // will detect bright areas whose luminosity > 0.2f;
}

void draw() {
    loadPixels();  
  updatePixels(); 
    theBlobDetection.computeBlobs(img.pixels);
    drawBlobsAndEdges(true,true);
}
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)
    {

      if (drawEdges)
      {
        strokeWeight(3);
        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);
        if(((b.w*width)*(b.h*height)<20000) && ((b.w*width)*(b.h*height)>10000))
        rect(
          b.xMin*width,b.yMin*height,
          b.w*width,b.h*height
          );
      }

    }

      }
}

filtered

this is the results but i don't know how to count the blobs

For bloblscanner library: the problem with this library is that it displays 3 blobs but it still counts the ones that is not displayed too

import Blobscanner.*;

PImage img; 
color boundingBoxCol = color(255, 0, 0);
int boundingBoxThickness = 1;
int bn;
int contourColor =color(0,0,255);
int minimumWeight = 20000;
Detector bd;

void setup() 
{
img = loadImage("cars.jpg");

size(img.width, img.height);
img.filter(THRESHOLD);
bd = new Detector( this, 0, 0, img.width, img.height, 255 );

image(img, 0, 0);

}

void draw(){
img.loadPixels();
bd.imageFindBlobs(img);
//bd.findBlobs(img.pixels, img.width, img.height);
bd.loadBlobsFeatures();// to call always before to use a method returning or processing a blob feature
bd.weightBlobs(true);
bd.drawSelectBox(minimumWeight, boundingBoxCol, boundingBoxThickness);
println(bd.getBlobsNumber() + " BLOBS FOUND.");

} 

scanner

its reads as there is 138 detected while there is only 3 blobs displayed. Help please

Greets,Ernest

Tagged:

Answers

  • I don't know about this library much but I can tell you that these 138 blobs found are actual blobs found in the image. Since you can't see those blobs because they are small. You can avoid this by setting the blob weight threshold. I don't know if this function exists in this library but it is there in blobscanner library. Please read its documentation.

  • Thank you so much for answering. ya i actually thought of that and i actually did the weight threshold with bd.drawSelectBox(minimumWeight, boundingBoxCol, boundingBoxThickness); while i set miniumWeight to 20000 but the 138 blobs still exist...

  • Answer ✓

    Okay then don't use default threshold while filtering the image. Try adjusting it manually.

Sign In or Register to comment.