Blob Detection
Learn to detect blobs in a mask, and extract blob measurements.
Now that we have a mask where all the objects of interest are well segmented, the next step is to count these objects and measure their shapes. Blob analysis is the measurement of binary object properties.
We have the following mask of the green anchor dowels.
Our task for this lesson is to isolate each object. We need the centroid, area, bounding box, and moments of each blob in the mask. Blob moments provide information about the orientation and shape of the blob. The blob moment definition will be provided below.
For our task, we won’t filter objects based on their moments, but we’ll need their moments m00, m01, and m10 to calculate the area and centroid of each blob.
Preparation of the mask for cv2.SimpleBlobDetector_create()
The OpenCV library offers a simple blob detector aptly named SimpleBlobDetector
. As we’ll see, this class has various peculiarities requiring some care and extra work. This will allow us to introduce a few new functions.
For starters, SimpleBlobDetector
expects black blobs on a white background. Since our mask has white blobs on a black background, we need the create the inverse mask.
There is also a problem associated with blobs ...