I am using bounding boxes to find text in an image and sometimes the boxes are just slightly too small and cut off parts of text on the top and bottom.
So I thought I'd extend every bounding box just a little to compensate for the inaccuracy.
double Z = 10;
cv::Rect extended( appRect.x-Z, appRect.y-Z, appRect.width+2*Z, appRect.height+2*Z);
appRect
being a cv::Rect
This does what I am looking for however it seems that sometimes it takes the bounding box out of bounds.
Giving me this error:
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in Mat
How can I check that the rect is within the boundaries of the image and avoid this error while still expanding the bounding boxes?