cv::Rect 的异常处理
Exception Handling for cv::Rect
我有边界框,我想用这个边界框裁剪图像。
但是我想增加边界框的大小,所以我这样做
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;
}
对于最右边靠近边框的组件,如果我增加宽度,这将是错误的。如果组件位于靠近边框的底部,则高度也是如此
有什么方法可以处理此异常吗?
您收到错误是因为&
需要 l 值,而 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)
相关文章:
- 为什么我应该在异常处理中使用std::cerr而不是std::cout
- 当我使用 C++ 中的 C# dll 来使用 Selenium 时,存在异常处理问题
- Firebase C++VS2018 SDL2-在Firebase::app::create(..)上执行异常处理
- 使用 stoi 功能进行异常处理
- 子系统中的异常处理:本机
- 与异常处理程序中的操作员<<不匹配
- 数组 C++ 上的异常处理程序
- 异常处理:如果用户输入不是三个特定字符之一
- C++ 异常处理错误输出
- 视觉 std::矢量无异常:警告 C4530:使用了C++异常处理程序,但未启用展开语义.指定 /EHsc
- C++交换机状态异常处理
- 在字符串类上的成员函数和out_of_range异常处理
- 奇怪的消息 (_Base_bitset::_M_do_to_ulong) 从溢出异常处理程序中打印出来
- 执行视觉工作室异常处理模式
- 为什么隐式转换在异常处理中从派生到基?
- C++执行期间的类成员函数错误/异常处理
- C++ 中未处理的异常处理程序
- 用户定义的异常处理
- C :ScopeGuard vs返回支票和异常处理
- cv::Rect 的异常处理