#include <opencv2/opencv.hpp>
void extractMatsFrom3DMat(cv::Mat& threeDMat) {
std::cout << "dims=" << threeDMat.dims << std::endl;
std::cout << "chanel=" << threeDMat.channels() << std::endl;
std::cout << "size=" << threeDMat.size << std::endl;
if (threeDMat.dims == 3 && threeDMat.size[0] == 4)
{
for (int i = 0; i < 4; ++i)
{
cv::Mat singleMat = threeDMat.rowRange(i, i + 1).clone();
std::cout << singleMat.size << std::endl;
cv::Mat newMat = singleMat.reshape(1, 256);
std::cout << newMat.size << std::endl;
cv::imshow("w", newMat);
cv::waitKey();
}
}
else
{
std::cerr << "Input Mat does not have the expected dimensions." << std::endl;
}
}
int main() {
int size[3]{4,256,256};
cv::Mat threeDMat(3, size, CV_32F);
threeDMat.setTo(1);
extractMatsFrom3DMat(threeDMat);
return 0;
}