Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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