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细节可参考其他博客
效果如下:
![](https://i-blog.csdnimg.cn/blog_migrate/e9fc108e81803378cbe37ff8c853de47.png)
![](https://i-blog.csdnimg.cn/blog_migrate/ad943ed9344b4a3cff17cbdb7215f54a.png)
若opencv加载深度数据集失败,就请参考这篇博客,这是作者在加载深度数据时失败所写解决方法:https://mp.csdn.net/mp_blog/creation/editor/new/128924956