此功能:
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;
}
答案 0 :(得分: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;
}