Error Exception Handling For Cv::Rect opencv in C++
I have bounding box and I want to crop image with this bounding box.
However I want to increase the size of the bounding box, so I do
if ((roi_.x - 5) > 0) // i test here in case the component at the left near border
//we do not minus otherwise it will be error
{
roi_.x += (-5);
}
if ((roi_.y - 5) > 0) // i test here in case the component at the left near border
//we do not minus otherwise it will be error
{
roi_.y += (-5);
}
if (&(roi_ + cv::Size(10, 0)) != NULL)
{
roi_.width += 10;
}
if (&(roi_ + cv::Size(0, 10)) != NULL)
{
roi_.height += 10;
}
For the component at the most right near the border if I increase the width it will be error. The same thing for the height in case the component is at the bottom near the border
Are there any ways to handle this exception?