How to merge 3 matrices into 1 in opencv?

后端 未结 3 2132
离开以前
离开以前 2021-01-06 18:33

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

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 19:14

    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.

    Here's a sample code:

    vector 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;
    

    Here's the result:

    [1, 2, 3;
      1, 2, 3;
      1, 2, 3;
      1, 2, 3]
    Program ended with exit code: 1
    

    Similarly, if you want to do it vertically (stack by rows), use vconcat.

提交回复
热议问题