如何在opencv中将3个矩阵合并为1个? [英] How to merge 3 matrices into 1 in opencv?
本文介绍了如何在opencv中将3个矩阵合并为1个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个矩阵,每个矩阵的大小为4x1
.我想将所有这些矩阵复制到另一个大小为4x3
的矩阵,并将其命名为R
.有什么聪明的方法吗?
I have three matrices, each of size 4x1
. I want to copy all of these matrices to another matrix of size 4x3
and call it R
. Is there a smart way to do it?
推荐答案
您可以仅使用hconcat进行水平串联.您可以按矩阵使用它,例如hconcat(mat1,mat2,R),或将其直接应用于向量或矩阵数组.
You can just use hconcat for horizontal concatenation. You can use it per matrix, e.g. hconcat( mat1, mat2, R ), or apply it directly on a vector or array of matrices.
这是示例代码:
vector<Mat> matrices = {
Mat(4, 1, CV_8UC1, Scalar(1)),
Mat(4, 1, CV_8UC1, Scalar(2)),
Mat(4, 1, CV_8UC1, Scalar(3)),
};
Mat R;
hconcat( matrices, R );
cout << R << endl;
结果如下:
[1, 2, 3;
1, 2, 3;
1, 2, 3;
1, 2, 3]
Program ended with exit code: 1
类似地,如果您想垂直进行(按行堆叠),请使用vconcat.
Similarly, if you want to do it vertically (stack by rows), use vconcat.
这篇关于如何在opencv中将3个矩阵合并为1个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文