[英]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值 ,這不是roi_ + cv::Size(10, 0)
roi_ + cv::Size(0, 10)
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.