简体   繁体   English

cv :: Rect的异常处理

[英]Exception Handling for cv::Rect

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? 有没有办法处理这个例外?

You get the error because & requires the l-value , which are not for both roi_ + cv::Size(10, 0) and roi_ + cv::Size(0, 10) . 你得到错误是因为&需要l值 ,这不是roi_ + cv::Size(10, 0) roi_ + cv::Size(0, 10) roi_ + cv::Size(10, 0)roi_ + cv::Size(0, 10)

You need to change 你需要改变

if (&(roi_ + cv::Size(10, 0)) != NULL)
...
if (&(roi_ + cv::Size(0, 10)) != NULL)

to

if ((roi_.x + roi_.width + 10) < img.cols)
...
if ((roi_.y + roi_.height + 10) < img.rows)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM