C++ 如何调整投资回报率?

C++ 如何调整投资回报率?,c++,opencv,C++,Opencv,我想根据比例因子调整投资回报率。 我正在尝试这个: 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 << ", "

我想根据比例因子调整投资回报率。 我正在尝试这个:

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);
以及:


OpenCV错误:断言失败(0您可以手动检查/约束ROI边界或使用
Rect
重叠,如下所示:

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

你的投资回报率是什么类型?应该是2d或2f点!
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
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);