程序修改与运行---构建实时系统
源文件下载:
https://download.csdn.net/download/ly1997th/10394408
https://download.csdn.net/download/ly1997th/1039440
1. 从D435中获取color和depth数据,在librealSense/examples/save-to-disk中,可以看到数据是如何获取的。首先得到depth数据,然后获得color数据,然后存入磁盘。在这里,我们可以使用这种方法获得数据(可以尝试不去存磁盘,直接把realsense的数据流转变为Mat类型,传给ORB_SLAM,但是我没有做出来)同时,需要注意的是,ORB_SLAM还需要时间戳,在veido_frame类(其实是在基类frame)中可以找到函数get_timestamp(),获得时间戳。最后,将这部分内容转化为函数
double LoadImages(cv::Mat &imRGB,cv::Mat &imD)
1.1 原始示例中代码
for (auto&& frame : pipe.wait_for_frames())
{
// We can only save video frames as pngs, so we skip the rest
if (auto vf = frame.as<rs2::video_frame>())
{
auto stream = frame.get_profile().stream_type();
// Use the colorizer to get an rgb image for the depth stream
if (vf.is<rs2::depth_frame>()) vf = color_map(frame);
// Write images to disk
std::stringstream png_file;
png_file << "rs-save-to-disk-output-" << vf.get_profile().stream_name() << ".png";
stbi_write_png(png_file.str().c_str(), vf.get_width(), vf.get_height(),
vf.get_bytes_per_pixel(), vf.get_data(), vf.get_stride_in_bytes());
std::cout << "Saved " << png_file.str() << std::endl;
// Record per-frame metadata for UVC streams
// std::stringstream csv_file;
// csv_file << "rs-save-to-disk-output-" << vf.get_profile().stream_name()
// << "-metadata.csv";
// metadata_to_csv(vf, csv_file.str());
}
}
1.2 double LoadImages(cv::Mat &imRGB,cv::Mat &imD)
double LoadImages(cv::Mat &imRGB,cv::Mat &imD)
{
// Declare depth colorizer for pretty visualization of depth data
rs2::colorizer color_map;
// Declare RealSense pipeline, encapsulating the actual device and sensors
rs2::pipeline pipe;
// Start streaming with default recommended configuration
pipe.start();
// Wait for the next set of frames from the camera. Now that autoexposure, etc.
// has settled, we will write these to disk
int flag=0;
double timestamp=0.0;
int ping=1000;
for (auto&& frame : pipe.wait_for_frames(ping))
{
// We can only save video frames as pngs, so we sk