opencv c++ 创建多维数组,类似numpy数组

#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 << "Extracted Mat " << i + 1 << " with dimensions: " << singleMat.size[0] << " x " << singleMat.size[1] << std::endl;*/
            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);  // 创建一个示例 3D Mat,假设它有 4 层,每层大小为 256 x 25
    threeDMat.setTo(1);

    extractMatsFrom3DMat(threeDMat);  // 调用函数来提取并打印每个 2D Mat 的尺寸信息

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值