title: OpenCV ROI Out-of-bounds: Fill with black?
body: <p>I'm using OpenCV to get a small rectangular ROI from a large image and save the ROI to a file. Sometimes, the ROI goes out of bounds of the image. I need a way to make the resulting Mat show the portion of the large image that is within bounds, and show black for the rest.</p>
  
  <p>To help explain, image that you have an image that is a map of an area. I know where a person is on the map, and want to take a 500x500 pixel section of the map with their location in the center. But when the user gets to the edge of the map, part of this 500x500 section will need to be "off the map". So I would like it to fill it in with black.</p>
  
  <p>Preferably, OpenCV would be able to gracefully handle out-of-bounds ROIs (e.g. negative top left corner values) by filling in with black (like it does when you rotate an image with <code>warpAffine</code>) but that doesn't seem to be the case. Any suggestions for how to accomplish this goal?</p>