Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
//if all you need is the cropped image inside the rect:
Mat cropped = img(Rect(40,40,300,300));

// if instead, you want to mask out(blacken) everthing BUT the rect in your image,
// make a mask imag, 8bit, same size as your image:
mask = cv::Mat::zeros(img.size(),CV_8UC1);

// mark some rect as white: (the 'pass through' area)
mask(Rect(60,60,300,300)) = 255;

// 'and' your image with the mask
img &= mask;