OpenCV/C++:将 Mat 中的行/列复制到另一个?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6670818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenCV/C++: Copying a row/column in a Mat to another?
提问by NOT A DOG NO SERIOUSLY
I know I can do this by copying each element myself, but is there a method that does it for me? I tried mat2.copyTo(mat1.row(0))
but that doesn't work.
我知道我可以通过自己复制每个元素来做到这一点,但是有没有适合我的方法?我试过了,mat2.copyTo(mat1.row(0))
但这不起作用。
回答by Ela782
Try
尝试
Mat mat1row = mat1.row(0);
mat2.copyTo(mat1row);
(assuming mat2 has the same size as the destination row).
(假设 mat2 与目标行的大小相同)。
That should do the job and is more clear.
这应该可以完成工作并且更清楚。
Edit: This is even shorter and recommended by the official documentation:
编辑:这更短,官方文档推荐:
A.row(j).copyTo(A.row(i));
More details on this in the official documentation: http://docs.opencv.org/modules/core/doc/basic_structures.html#Mat%20Mat%3a%3arow%28int%20y%29%20const
官方文档中的更多详细信息:http: //docs.opencv.org/modules/core/doc/basic_structures.html#Mat%20Mat%3a%3arow%28int%20y%29%20const