How to calcuate area of the blob's hole?(cvBlob)
Hi all: I want to know the area of the blob's hole. How to implement ??? please help me. Thanks!
Hi all: I want to know the area of the blob's hole. How to implement ??? please help me. Thanks!
Hi. You can use the findContours function to detect all contours in your image. It returns also a hierarchy of the contours which provides you information about the image topology. If you then sum up the area of the contours in the second hierarchy level you have the result.
Here is an example of how to use it.
Here is my rough attempt at the code. I am assuming that there is only one blob though I see that there ate two in your example. You can modify the code to suit your needs.
for ( i = 0; i < blobs.GetNumBlobs(); i++ )
{
CBlob& current_blob = blobs.GetBlob ( i );
roi = current_blob.GetBoundingBox();
cv::Mat blob_roi = cv::Mat ( image, roi );
bitwise_not ( blob_roi, blob_roi );
IplImage ipl_blob_roi = blob_roi.operator IplImage();
CBlobResult& inv_blobs = CBlobResult ( &ipl_blob_roi, NULL, 0 );
int blob_area = inv_blobs.GetBlob(0).Area();
}
Hi Yes. cvBlobsLib reporting is different. I get the answer is 17275 & 30429.5. The code is here: _blobs=CBlobResult(dst_img,NULL,0); for(int i=0;i<_blobs.GetNumBlobs();i++) { blob=_blobs.GetBlob(i); p1.x=(int)blob.MinX(); p1.y=(int)blob.MinY(); p2.x=(int)blob.MaxX(); p2.y=(int)blob.MaxY(); double area=blob.Area(); cvRectangle(src_img,p1,p2,CV_RGB(255,0,0),2,8,0); }
Since you are using the cvBlob, I'll suggest setting up an ROI corresponding to the blob. Invert the image in the ROI (using bitwise_not) and find the blobs on that. And then, you can get the area and other parameters on the newfound blobs.
Asked: 2012-12-20 08:45:28 -0600
Seen: 3,744 times
Last updated: Dec 20 '12