如何将2d图像分配给3D OpenCV Mat的平面,然后沿不同的轴提取2D Mats? [英] How to assign 2d images to planes of a 3d OpenCV Mat, then extract 2D Mats along a different axis?
问题描述
我想从堆叠的2D Mats制作3D Mat,然后沿着3D Mat的不同轴拉出2D Mats。我知道我可以建立这个手动访问每一行或每一个图像的每一行,但有一个更好的做,像下面这样?
I want to make a 3D Mat out of stacked 2D Mats and then pull out 2D Mats along a different axis of the 3D Mat. I know I can build this up manually accessing every row or col of every image but is there a better to do it like the following?
vector<cv::Mat> images;
...用图像填充向量
... populate vector with images
int sz[] = {images[0].rows, images[0].cols, images.size()}
cv::Mat cube(3, sz, images[0].type() );
cube = Scalar(0);
for (int i = 0; i < images.size(); i++) {
b $ b
...将图片放入3d mat
... place images into 3d mat
}
vector<cv::Mat> image_rows;
for (int i = 0; i < images[0].rows(); i++) {
...按照3D立方体矩阵的宽度和深度将图像平面推入image_rows
... push image planes into image_rows along width and depth of 3D cube matrix
}
推荐答案
我对opencv做了很多工作,就我所知,这是最好的方法。你可以做一个更高维度的向量Mat,但然后你的访问将更少干净。坚持矢量它是你最好的打赌。
I have done a lot of work with opencv and as far as I know that is the best way to do it. You could make a Mat of higher dimensional vectors but then your access would be even less clean. Stick to the vector its your best bet.
这篇关于如何将2d图像分配给3D OpenCV Mat的平面,然后沿不同的轴提取2D Mats?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!