gpt4 book ai didi

c++ - 在两个 channel 矩阵中插入数据

转载 作者:行者123 更新时间:2023-11-28 05:58:00 24 4
gpt4 key购买 nike

我是 OpenCV 及其开发的新手。我有两个 channel 矩阵

Mat alleigen( Size(3,3) , CV_32FC2) 

我有数据:

A=[1,2,3]

B=[4,5,6]

c=[7,8,9]

我想像M矩阵一样插入

M= [1 4 7
2 5 8
3 6 9]

我如何在 OpenCV 中做到这一点?

最佳答案

您可能不想要一个 2 channel 矩阵,而是一个简单的二维矩阵:

以下代码将产生所需的输出:

A:
[1, 2, 3]

B:
[4, 5, 6]

C:
[7, 8, 9]

M:
[1, 2, 3;
4, 5, 6;
7, 8, 9]

代码:

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;

int main()
{
Mat1f A = (Mat1f(1, 3) << 1, 2, 3);
Mat1f B = (Mat1f(1, 3) << 4, 5, 6);
Mat1f C = (Mat1f(1, 3) << 7, 8, 9);

Mat1f M(3,3);

A.copyTo(M.rowRange(0, 1));
B.copyTo(M.rowRange(1, 2));
C.copyTo(M.rowRange(2, 3));

cout << "A: " << endl << A << endl << endl;
cout << "B: " << endl << B << endl << endl;
cout << "C: " << endl << C << endl << endl;
cout << "M: " << endl << M << endl << endl;

return 0;
}

关于c++ - 在两个 channel 矩阵中插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33803912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com