Cant display largest blob in new image.

12 views
Skip to first unread message

legolas

unread,
Sep 1, 2011, 8:27:39 AM9/1/11
to cvb...@googlegroups.com
Hi. I am new to the group. I have a binary image and i want to display the largest only in the new image. However i fail. Below is my code:

                        //load image
IplImage * inputImage = cvLoadImage("fill.jpg");

CBlobResult blobs;
blobs = CBlobResult( inputImage, NULL, 0 ); 

// number of blobs
int n = blobs.GetNumBlobs();
cout<<"number of blobs: "<<n<<endl;
CBlob *currentBlob;
CBlob *maxBlob;
double max=0.0,currentBlobArea=0.0;
IplImage * imgBlob=cvCreateImage(cvGetSize(inputImage),IPL_DEPTH_8U,1);
for (int i=0; i<n; i++ )
{
currentBlob = blobs.GetBlob(i);
//if currentBlob area is largest, fill the imgBlob;
currentBlobArea = currentBlob->Area();
//cout<<"area: "<<currentBlobArea<<endl;
if(currentBlobArea>max){
maxBlob = currentBlobArea;
}
}
                        //cout<<"largest area is: "<<max<<endl;
maxBlob->FillBlob(imgBlob, CV_RGB(255,255,255));

cvShowImage("blob",imgBlob);
cvSaveImage("blob.jpg",imgBlob);
cvWaitKey(0);
cvReleaseImage(&imgBlob);

Is the way i create new image wrong?

Please help me. Thank you.
Reply all
Reply to author
Forward
0 new messages