出于性能原因,我只对在图像的下半部分执行HoughLinesP感兴趣,所以我想将一个图像的底部复制到另一个相同大小的图像。保持图像尺寸很重要,因为我需要保持相对于原始图像检测到的线条。
我尝试使用以下代码调整this解决方案:
int startpoint{ 240 };
cv::Mat houghlinesmat{ image.size(), image.type(), cv::Scalar(0) };
houghlinesmat.setTo(0);
image.copyTo( houghlinesmat(cv::Rect(0,
startpoint,
image.cols,
image.rows - startpoint)) );
但是,我总是收到一个类似于this示例的copyTo断言错误。但是,在我看来,这不是一行或一列的问题。似乎更多的是我无法复制cv:rect小于输出而没有错误。知道什么是缺失的吗?
答案 0 :(得分:0)
找到最终解决方案here的一些方向,请参阅最后评论。
改编:
image( cv::Rect(0,
startpoint,
image.cols,
image.rows -
startpoint)).copyTo(houghlinesmat(cv::Rect(0,
startpoint,
image.cols,
image.rows -
startpoint)));
最后看起来有点乱,但正是我想要的。基本上我没有指定源区域和目标区域,因此大小不匹配。
答案 1 :(得分:-1)
试试这个:
image.copyTo( houghlinesmat, cv::Rect(0,
startpoint,
image.cols,
image.rows - startpoint));
小心面具的大小。