首页 > 解决方案 > OpenCV mat of mats

问题描述

What is the best way to represent with OpenCV(C++) a mat of mats? At the moment in my code, I use a vector of vector<Mat> and I need the benefits of using a matrix.

标签: c++opencv

解决方案


仅限于我的搜索,不幸的是,Opencv-C++ 中没有定义这样的东西(python 版本有它)。矢量是你所能得到的。

尽管如果您的所有图像都是灰度并且具有相同的大小,您可以定义一个 n 通道图像并将每个图像放入其中一个通道中,例如:

Mat im1 = Mat::ones(n_row , n_col , CV_8UC1);
Mat im2 = Mat::ones(n_row , n_col , CV_8UC1);
Mat im3 = Mat::ones(n_row , n_col , CV_8UC1);
... // n similar images...

Mat img(n_row , n_col , CV_8UC(n));

vector<Mat> vec;

vec.push_back(im1);
vec.push_back(im2);
vec.push_back(im3);
... // push back all the n images

merge(vec,img); 

推荐阅读