首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何调整投资回报率?

如何调整投资回报率?
EN

Stack Overflow用户
提问于 2014-04-04 20:57:33
回答 1查看 3.4K关注 0票数 3

我想相应地调整ROI的比例因子。我试着这样做:

代码语言:javascript
复制
std::cout << roi.x << ", " << roi.y << std::endl;
std::cout << roi.x + roi.width << ", " << roi.y + roi.height << std::endl;

std::cout << img.size().width << ", " << img.size().height << std::endl << std::endl;

scale = 0.1; // 10%

cv::Rect new_size(
        roi.x*(1-scale),
        roi.y*(1-scale),
        (roi.x + roi.width)*(1+scale),
        (roi.y + roi.height)*(1+scale));
cv::Mat tmp = img(new_size);

它打印:

代码语言:javascript
复制
828, 142
892, 206
2048, 1150

281, 173
356, 248
2048, 1150

1025, 168
1100, 243
2048, 1150

和:

代码语言:javascript
复制
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in Mat, file /tmp/opencv-TqF1/opencv-2.4.7.1/modules/core/src/matrix.cpp, line 323
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv-TqF1/opencv-2.4.7.1/modules/core/src/matrix.cpp:323: error: (-215) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function Mat

嗯,我想我正在尝试设置一个与我的图像边界重叠的ROI。我的问题是:我必须手动执行此操作吗?如果是,如何在达到边界之前进行扩展?OpenCV应该有一个这样的方法,对吧?我一直在寻找,我可以找到adjustROI,但我不确定如何使用它。

EN

回答 1

Stack Overflow用户

发布于 2014-09-15 15:09:46

您可以手动检查/约束感兴趣区域边界或使用Rect重叠,如下所示:

代码语言:javascript
复制
cv::Rect new_size(/*Construct rect here*/);
cv::Rect imgBounds(0,0,img.cols,img.rows);
new_size = new_size & imageBounds;
// Now you can do the following without worrying (except in the case that new_size is empty!!)
cv::Mat tmp = img(new_size);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22863515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档