Ask Your Question
0

How to calcuate area of the blob's hole?(cvBlob)

asked 2012-12-20 08:45:28 -0600

wuling gravatar image

Hi all: I want to know the area of the blob's hole. How to implement ??? please help me. Thanks!未命名2.bmp

edit retag flag offensive close merge delete

3 answers

Sort by » oldest newest most voted
1

answered 2012-12-20 09:20:05 -0600

Siegfried gravatar image

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.

edit flag offensive delete link more
0

answered 2012-12-20 11:21:07 -0600

unxnut gravatar image

updated 2012-12-20 15:07:22 -0600

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();
}
edit flag offensive delete link more

Comments

Hi unxnut I ty use cvblobslib ,but i find a question! The two area of the blobs without holes is 17544 & 30891 . I use ni vision is the same result, espect cvblobslib v8,3

wuling gravatar imagewuling ( 2012-12-21 05:37:17 -0600 )edit

I did not follow your comment. Is cvBlobsLib reporting something different than what you expected? 8.3 is the most current version as far as I know.

unxnut gravatar imageunxnut ( 2012-12-21 07:22:19 -0600 )edit

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); }

wuling gravatar imagewuling ( 2012-12-21 08:07:12 -0600 )edit

Cristóbal tell me: "Each blob has a list of inner contours, you can calculate the area of them directly."

cvBlob.internalContours

You're welcome!

so i try again!

wuling gravatar imagewuling ( 2012-12-21 08:28:38 -0600 )edit

Hi unxnut, I don't know cvbloblibs has any bug or not. May be Connected-component labeling using 4-connected not 8-connected

wuling gravatar imagewuling ( 2012-12-21 10:22:18 -0600 )edit
0

answered 2012-12-20 09:58:15 -0600

unxnut gravatar image

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.

edit flag offensive delete link more

Comments

dear unxnut I try overwrite cvLabel function. I know how many holes in the blob. But I don't the holes area!

wuling gravatar imagewuling ( 2012-12-20 10:06:41 -0600 )edit

Question Tools

Stats

Asked: 2012-12-20 08:45:28 -0600

Seen: 3,731 times

Last updated: Dec 20 '12