C++ 使用opencv加载并显示RGB图像和深度图像

该文章展示了一段C++代码,用于读取和显示RGB图像以及存储在XML文件中的深度图像。通过OpenCV库,代码首先加载并显示一系列JPEG格式的RGB图像,然后读取并显示相应的XML格式的深度图像。当遇到OpenCV加载深度数据集问题时,文章提供了一个参考链接来解决此类问题。
摘要由CSDN通过智能技术生成

rgb图像是一般的彩色图像格式,深度图像是存储在xml文件中,c++读取代码如下:

#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <fstream>

using namespace cv;
using namespace std;
int main() {
    //加载并显示rgb图像
    std::string pattern_jpg = "C:\\Users\\Carry\\Downloads\\RGB\\RGB\\s01_e01\\*.jpg";

    std::vector<cv::String> image_files;
    cv::glob(pattern_jpg, image_files);
    if (image_files.size() == 0) {
        std::cout << "No image files[jpg]" << std::endl;
        return 0;
    }

    for (unsigned int frame = 0; frame < image_files.size(); ++frame) {//image_file.size()代表文件中总共的图片个数
        Mat image = cv::imread(image_files[frame]);
        imshow("RGB", image);
        waitKey(30);

    }

    //加载并显示深度图像
    std::string pattern_xml = "C:\\Users\\Carry\\Downloads\\depth\\depth\\s01_e01\\*.xml";

    std::vector<cv::String> xml_files;
    cv::glob(pattern_xml, xml_files);
    if (xml_files.size() == 0) {
        std::cout << "No xml files[jpg]" << std::endl;
        return 0;
    }

    for (unsigned int frame = 0; frame < xml_files.size(); ++frame) {//image_file.size()代表文件中总共的图片个数
        FileStorage fsread(xml_files[frame], FileStorage::READ);
        Mat dst;
        string str = xml_files[frame].substr(xml_files[frame].find_last_of('\\') + 1, xml_files[frame].find_last_of('.')- xml_files[frame].find_last_of('\\')-1);
        fsread[str] >> dst; // 读出节点里的数据到dst矩阵中
        fsread.release();
        imshow("depath", dst);
        waitKey(30);
    }
}

当然,需要安装并配置opencv,配置opencv细节可参考其他博客

效果如下:

若opencv加载深度数据集失败,就请参考这篇博客,这是作者在加载深度数据时失败所写解决方法:https://mp.csdn.net/mp_blog/creation/editor/new/128924956

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值