繁体   English   中英

使用OpenCV将3D矩阵导入2D矩阵

[英]Import 2D matrix in 3D matrix using OpenCV

该功能:

 filtro.kernel(n, mat)

返回大小为15x15的2D矩阵,有没有办法将从for周期计算出的所有12个矩阵相加到大小为12,15,15的3D矩阵中?

#include <opencv2/core/core.hpp>
#include <opencv2/core/core.hpp>
#include "filter.h"
#include <iostream>


int main(){
    using namespace cv;
    using namespace std;
    cv::Mat mat = cv::Mat::zeros(15, 15, CV_32S);
    filter filtro;

    for (int n = 0; n < 12; n++){
        filtro.kernel(n, mat);
        cout<<"Angle Matrix"<<endl;
        cout<< n*15 <<endl;
        cout<< mat <<endl;
    }
return 0;
}

您可以使用cv::merge创建multi-channels matrix 但请注意,渠道维度是最后一个维度。 12 (15,15) => (15,15,12)

尝试这个:

#include <opencv2/core/core.hpp>
#include <opencv2/core/core.hpp>
#include "filter.h"
#include <iostream>


int main(){
    using namespace cv;
    using namespace std;
    filter filtro;

    // Create a vector of Mat 
    vector<Mat> mats;

    for (int n = 0; n < 12; n++){  
        cv::Mat mat = cv::Mat::zeros(15, 15, CV_32S);
        filtro.kernel(n, mat);
        cout<<"Angle Matrix"<<endl;
        cout<< n*15 <<endl;
        cout<< mat <<endl;   
        mats.push_back(mat);
    }

    // Merge the Mats
    Mat dst;
    merge(mats, dst);

    return 0;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM