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++) {
... place images into 3d mat
开发者_Python百科}
vector<cv::Mat> image_rows;
for (int i = 0; i < images[0].rows(); i++) {
... push image planes into image_rows along width and depth of 3D cube matrix
}
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.
精彩评论