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()代表文件中總共的圖片個數(shù)
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()代表文件中總共的圖片個數(shù)
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; // 讀出節(jié)點(diǎn)里的數(shù)據(jù)到dst矩陣中
fsread.release();
imshow("depath", dst);
waitKey(30);
}
}
當(dāng)然,需要安裝并配置opencv,配置opencv細(xì)節(jié)可參考其他博客
效果如下:文章來源:http://www.zghlxwxcb.cn/news/detail-531174.html


若opencv加載深度數(shù)據(jù)集失敗,就請參考這篇博客,這是作者在加載深度數(shù)據(jù)時失敗所寫解決方法:https://mp.csdn.net/mp_blog/creation/editor/new/128924956文章來源地址http://www.zghlxwxcb.cn/news/detail-531174.html
到了這里,關(guān)于C++ 使用opencv加載并顯示RGB圖像和深度圖像的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!