使用 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;
}
相关文章:
- 2D数组来自文本输入,中间有空格
- 将值指定给向量(2D)的向量中的某个位置
- 尝试导入pybind-opencv模块时出现libgtk错误
- 如何使用用户输入在C++中正确填充2D数组
- 导入库可以跨dll版本工作吗
- 如何在C++中检查2D数组中负值的输入验证
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- 建议在运行时将带有类实例的列表从c++导入qml
- 在 2D 向量中使用第三个 [ ] 有什么意义?
- 四边形的 2D 旋转
- 打印第二列时的2d字符矢量打印空间
- 导入/导出变量时出错
- 如何将以逗号和空格分隔的整数读取到 2D 数组中?
- 如何在C++函数中声明静态 2D 数组?
- 我是 C++ 的初学者,我想知道如何在 2D 矢量中获取重复值
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 如何声明一个可以在整个程序中使用的全局 2d 3d 4d .. 数组(堆版本)变量?
- 将QT项目导入Visual Studio 2019会给我带来很多LNK2001错误
- 使用 OpenCV 在 3D 矩阵中导入 2D 矩阵
- 选择文本文件中的特定数据导入到c++的2d数组中