Ask Your Question

Revision history [back]

You could use boundingRect() to get bounding box for a contour. See tutorial here

Using the above bounding Rect you can save the image like

   Rect R=boundingRect(contour[i]); // Get bounding box for contour i
   Mat ROI=src(R); //Set ROI on source image
   imwrite("croped.jpg",ROI); //save ROI image

You could use boundingRect() to get bounding box for a contour. See tutorial here

Using the above bounding Rect you can save the image like

   Rect R=boundingRect(contour[i]); // Get bounding box for contour i
   Mat ROI=src(R); //Set ROI on source image
   imwrite("croped.jpg",ROI); imwrite("cropped.jpg",ROI); //save ROI image