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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 20:30:18  来源:igfitidea点击:

OpenCV/C++: Copying a row/column in a Mat to another?

c++opencv

提问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

回答by Russbear

Try

尝试

destMat.row(i) = (sourceMat.row(i) + 0);

It's not very pretty but it gets the job done. Also see this. Read the comments on Mat::row

它不是很漂亮,但它完成了工作。也看到这个。阅读 Mat::row 上的评论