【问题标题】:Exception Handling for cv::Rectcv::Rect 的异常处理
【发布时间】:2014-02-17 16:18:15
【问题描述】:

我有边界框,我想用这个边界框裁剪图像。

但是我想增加边界框的大小,所以我这样做了

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;
}

对于最靠近边框的组件,如果我增加宽度会出错。如果组件位于边框附近的底部,高度也是如此

有没有办法处理这个异常?

【问题讨论】:

    标签: c++ exception opencv exception-handling rect


    【解决方案1】:

    您收到错误是因为 & 需要 l 值,而 roi_ + cv::Size(10, 0)roi_ + cv::Size(0, 10) 不适用。

    你需要改变

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

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

    【讨论】:

    • roi_x.width 你的意思是 roi_.width 吗?
    • @sayvortana 是的,错别字。更新。 :)
    • 你能解释一下条件 (roi_.x + roi_.width + 10)
    • @sayvortana roi_.x+roi_.widthroi_ 的右x 位置,img.cols 是图像的宽度。
    猜你喜欢
    • 1970-01-01
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多