如何访问一个3D矩阵切片的OpenCV [英] How to access slices of a 3d matrix in OpenCV
问题描述
我想592 47x47阵列存储到一个47x47x592矩阵。我创建的3D矩阵如下:
I would like to store 592 47x47 arrays into a 47x47x592 Matrix. I created the 3d Matrix as follows:
int sizes[] = {47,47,592};
Mat 3dmat(3, sizes, CV_32FC1);
然后我想我可以通过使用一组范围如以下访问它。
I then thought I could access it by using a set of ranges as in the following.
Range ranges[3];
ranges[0] = Range::all();
ranges[1] = Range::all();
ranges[2] = Range(x,x+1) //within a for loop.
Mat 2dmat = 3dmat(ranges);
然而,当我尝试使用copyTo功能输入现有的数据集,这是行不通的。
However, when I try to use the copyTo function to input an existing data set, it does not work.
data.copyTo(2dmat); //data is my 47x47 matrix
的3D矩阵,当我这样做没有得到更新。
The 3d matrix does not get updated when I do this.
任何信息AP preciated!谢谢!
Any information is appreciated! Thanks!
编辑:我的592的矩阵存储在此3D矩阵,这样我可以稍后再访问另一个循环每一个单独的47x47矩阵。所以,我以后会做这样的事吧。
edit: I store the 592 matrices in this 3d matrix so that I can then later access each of the individual 47x47 matrices in another loop. So I would later do something of this sort:
2dmat = 3dmat(ranges);
2dmat.copyTo(data);
所以,我会再进行使用此数据矩阵的一些操作。并在循环的下一次迭代中,我会使用下一个存储的数据矩阵
So I would then perform some operations using this data matrix. And in the next iteration of the loop, I would use the next stored data matrix.
推荐答案
这是另类的,基于矢量的解决方案:
An alternative, vector-based solution:
std::vector<cv::Mat> mat(592, cv::Mat(47, 47, CV_32FC1)); // allocates 592 matrices sized 47 by 47
for(auto &m: mat) {
// do your processsing here
data.copyTo(m);
}
这篇关于如何访问一个3D矩阵切片的OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!