OpenCV复制断言错误 [英] OpenCV copyTo assert error
问题描述
在将一个Mat复制到另一个Mat的感兴趣区域时,我遇到了一个从未见过的错误.谷歌搜索并没有得到很多结果,而且似乎都没有意义.
While copying one Mat into the region of interest of another I came accross an error I've never seen before. Googling it didn't turn up many results and none of them seems to be relevant.
我提供了错误的屏幕截图以及Mat的一些属性.
I have included a screenshot of the error as well as some properties of the Mat's.
这是代码:
std::cout << "size height,width: " << size.height << ", " << size.width << std::endl;
cv::Mat tempResult(size.width, size.height, result.type());
std::cout << "tempResult cols,rows: " << tempResult.cols << ", " << tempResult.rows << std::endl;
std::cout << "tempResult type: " << tempResult.type() << std::endl;
std::cout << "tempResult channels: " << tempResult.channels() << std::endl;
std::cout << "result cols,rows: " << result.cols << ", " << result.rows << std::endl;
std::cout << "result type: " << result.type() << std::endl;
std::cout << "result channels: " << result.channels() << std::endl;
cv::Rect rect(0, 0, result.cols-1, result.rows-1);
std::cout << "rect size: " << rect.size() << std::endl;
result.copyTo(tempResult(rect));
推荐答案
cv::Mat::operator(cv::Rect roi)
方法提取与cv :: Rect roi大小相同的子矩阵.
但是,您定义了一个cv :: Rect对象,其中缺少1行和1个col,因此tempResult(rect)
返回的输出矩阵小于矩阵result
. cv::Mat::CopyTo
启动异常,因为要复制的输入小于输出参数.
The cv::Mat::operator(cv::Rect roi)
method extract a submatrix with the same size of the cv::Rect roi.
But you defined a cv::Rect object with 1 row and 1 col missing, so the output matrix returned by tempResult(rect)
is smaller the the matrix result
. cv::Mat::CopyTo
launch an exception because the input to copy is smaller than the output argument.
要解决此问题:
cv::Rect rect(0, 0, result.cols, result.rows);
这篇关于OpenCV复制断言错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!