OPENCV



Name blobs()
Examples blobs
import hypermedia.video.*;

OpenCV opencv;

void setup() {

    size( 640, 480 );

    // open video stream
    opencv = new OpenCV( this );
    opencv.capture( 640, 480 );

}

void draw() {

    background(192);

    opencv.read();           // grab frame from camera
    opencv.threshold(80);    // set black & white threshold 

    // find blobs
    Blob[] blobs = opencv.blobs( 10, width*height/2, 100, true, OpenCV.MAX_VERTICES*4 );

    // draw blob results
    for( int i=0; i<blobs.length; i++ ) {
        beginShape();
        for( int j=0; j<blobs[i].points.length; j++ ) {
            vertex( blobs[i].points[j].x, blobs[i].points[j].y );
        }
        endShape(CLOSE);
    }

}

Description Blob and contour detection.

This function looks for contours within the image, returning a list of Blob objects.

When searching for blobs, you must define the minimum and maximum size in pixels. For example, if you want to limit blobs to no larger than half the Region Of Interest, pass (width * height) / 2 for the maxArea.

Blobs are returned in order from largest to smallest.

Blob objects contain all the relevant information about each contour (area, length, centroid, isHole, …)

The optional maxVertices parameter, allows you to increase the overall number of points defining the contour of the blob. Use this parameter if for some reason your blob shapes are incomplete. Augementing this parameter can affect performance.

Careful! This function will damage the current buffered image while searching for contours. If you want to do any subsequent work with this image, you will need to call the restore() method after this one.

Syntax blobs(minArea, maxArea, maxBlobs, findHoles);
blobs(minArea, maxArea, maxBlobs, findHoles, maxVertices);
Parameters
minArea int : the minimum area to search for (total pixels)
maxArea int : the maximum area to search for (total pixels)
maxBlobs int : the maximim number of blobs to return
findHoles boolean : accept blobs fully inside of other blobs
maxVertices int : the maximum number of points used to define the contour
Return Blob[]
Usage Application