Ask Your Question

how to save ROI's detected in an image

asked 2013-03-27 04:07:38 -0600

updated 2015-10-03 13:15:13 -0600

Hi; In my project, i can extract Roi's from labelled image but i didn't know how to save them for a later use .i work with cvBlob to extract blobs . here is the procedure witch extract roi but it shows only the last Roi and not all of them.Can you help me please?

void extraireROI(IplImage* img,CvBlob *blob)
    int heigth =(blob->maxy)- (blob->miny);
    int width=(blob->maxx)- (blob->minx);
    int x=blob->minx;
    int y=blob->miny;
    cvSetImageROI(img,cvRect(x, y, width, heigth));
    IplImage* img2=cvCreateImage(cvGetSize(img),img->depth, 3);
    cvCopy(img, img2, NULL);

    /* always reset the Region of Interest */
    cvShowImage("ROI extraite ",img2);
void labelImage(IplImage *binaire,IplImage *img )

    // Label image and extract informations 
   IplImage *labelImg=cvCreateImage(cvGetSize(binaire), IPL_DEPTH_LABEL, 1);
    CvBlobs blobs;
     IplImage *roi;
    unsigned int result=cvLabel(binaire, labelImg, blobs);
     FilterArea(blobs, 500, 250000);
    cvRenderBlobs(labelImg, blobs, img, img);
     CvBlobs::iterator it=blobs.begin();
      CvBlob *blob=(*it).second;
      cout << "Blob #" << it->second->label << ": Area=" << it->second->area << ", Centroid=(" << it->second->centroid.x << ", " << it->second->centroid.y << ")" << endl;
    cvShowImage("image labellisée ",img);
edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2013-03-27 08:52:31 -0600

Basically when you create a region of interest, just save it by calling SaveImage function. Region of interest will be saved as long as you don't reset it.

However, move to the c++ interface, which makes this way easier to handle!

edit flag offensive delete link more

answered 2013-03-27 10:06:18 -0600

What is exactly that you want to accomplish? If you want to display only the ROIs, I would suggest you to:

  1. Create a blank new output image
  2. For each ROI create a mask image from the ROI and use copy() with the mask as 3rd argument to copy the ROI from the input image to the output.

As Steven pointed out, the C++ interface makes everything better.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-03-27 04:07:38 -0600

Seen: 1,703 times

Last updated: Mar 27 '13