Create a mat ROI for each contour blob?
How would one create multiple ROI Mat based on a
vector <vector < point >> contours.
I have this function
vector<vector<Point> > MarkCountours(Mat binaryImg)
{
vector<vector<Point> > contours;
Mat test = binaryImg.clone();
vector<Vec4i> hierarchy;
RNG rng(12345);
findContours( test, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
vector<vector<Point> > contours_poly( contours.size() );
vector<Rect> boundRect( contours.size() );
vector<Point2f>center( contours.size() );
vector<float>radius( contours.size() );
for( int i = 0; i < contours.size(); i++ )
{
approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
boundRect[i] = boundingRect( Mat(contours_poly[i]) );
}
Mat drawing = Mat::zeros( binaryImg.size(), CV_8UC3 );
for( int i = 0; i< contours.size(); i++ )
{
Scalar color = Scalar(255,0,255);
drawContours( drawing, contours_poly, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0 );
}
return contours;
}
This draws rectangle on the binary image, based on contours, but how do i based on those countours create multiple Mat which consist of ROI where the contours are in interest..
A simpler way to detect the bounding rect of the contour is the boundingRect. If you want to create more images with just the wanted contour, you can read this