intel realsense 深度相机深度图像处理API总结

文章目录

intel realsense 深度相机深度图像处理API总结

一.导入库文件

  1. 除高级功能外,其他所有功能都通过以下头文件提供
#include

二.开启数据流传输

  1. RealSense SDK2.0主要通过管道(pipeline)控制摄像机枚举以及流的处理

rs2::pipeline p;
  1. 通过配置和启动管道,就可以实现对流的处理

p.start();

三.获取图像帧数据

  1. 一旦配置了管道,我们就可以循环等待新的帧,wait_for_frames函数将阻塞程序,直到下一组帧的到达,这里的帧中包含了彩色相机与深度相机等相机采集到的帧数据

rs2::frameset frames = p.wait_for_frames();
  1. 要从帧数据中获取相对应的图像,可以使用get__frame 函数,其中可以取color或者depth
rs2::frame color_frame = frames.get_color_frame();
rs2::frame depth_frame = frames.get_depth_frame();
rs2::depth_frame depth_frame = frames.get_depth_frame();

  1. 使用rs2::depth_frame获取到的深度帧数据中包含图像的很多基础信息,可以使用get_***()函数获取相对应的信息

float units = depth_frame.get_units();
float width = depth_frame.get_width();
float height = depth_frame.get_height();
double timestamp = depth_frame.get_timestamp();
unsigned long long frame_number = depth_frame.get_frame_number();
float dist_to_center = depth_frame.get_distance(width / 2, height / 2);

四.使用OpenCV显示深度图像和高度图像

  1. 显示彩色图像 彩色图像只需要在创建OpenCV Mat对象时,将获取到的彩色图像的图像大小和数据的指针给Mat对象即可
rs2::frame color_frame = frames.get_color_frame();

cv::Mat frame_color(cv::Size(640, 480), CV_8UC3, (void*)color_frame.get_data(), cv::Mat::AUTO_STEP);

cv::imshow("color", frame_color);
cv::waitKey(1);
  1. 显示高度图像 获取到的高度图像帧需要先进行色彩转换,然后才能进行显示
  2. 创建色彩转换对象,参数可以是0-9(0 – Jet 1 – Classic 2 – WhiteToBlack 3 – BlackToWhite 4 – Bio 5 – Cold 6 – Warm 7 – Quantized 8 – Pattern 9 – Hue)

rs2::colorizer color_map(9);
  1. 获取高度帧数据时,进行颜色着色,然后转换为OpenCV的Mat对象进行显示
rs2::frame depth_frame = frames.get_depth_frame().apply_filter(color_map);
const int w = depth_frame.as<rs2::video_frame>().get_width();
const int h = depth_frame.as<rs2::video_frame>().get_height();
cv::Mat frame_depth(cv::Size(w, h), CV_8UC3, (void*)depth_frame.get_data(), cv::Mat::AUTO_STEP);

cv::imshow("depth", frame_depth);
cv::waitKey(1);

intel realsense 深度相机深度图像处理API总结
1 – Classic模式
intel realsense 深度相机深度图像处理API总结
intel realsense 深度相机深度图像处理API总结
intel realsense 深度相机深度图像处理API总结
intel realsense 深度相机深度图像处理API总结
intel realsense 深度相机深度图像处理API总结
intel realsense 深度相机深度图像处理API总结
intel realsense 深度相机深度图像处理API总结
intel realsense 深度相机深度图像处理API总结
intel realsense 深度相机深度图像处理API总结

五.使用过滤器对图像数据进行后处理

rs2::frameset为未经过处理的原始数据,也可以通过创建过滤器来对原始数据进行处理,得到想要得数据

1.深度阈值过滤器 rs2::threshold_filter

rs2::threshold_filter thr_filter(0, 1);
rs2::frameset frames = p.wait_for_frames();
frames = thr_filter.process(frames);
rs2::frame color_frame = frames.get_color_frame();
rs2::frame depth_frame = frames.get_depth_frame().apply_filter(color_map);
const int w = depth_frame.as<rs2::video_frame>().get_width();
const int h = depth_frame.as<rs2::video_frame>().get_height();

cv::Mat frame_color(cv::Size(640, 480), CV_8UC3, (void*)color_frame.get_data(), cv::Mat::AUTO_STEP);
cv::Mat frame_depth(cv::Size(w, h), CV_8UC3, (void*)depth_frame.get_data(), cv::Mat::AUTO_STEP);

cv::imshow("color", frame_color);
cv::imshow("depth", frame_depth);

cv::waitKey(1);

intel realsense 深度相机深度图像处理API总结
intel realsense 深度相机深度图像处理API总结

2.高度图像与彩色图像的视野对齐

由于硬件原因,左右两侧摄像头与中间的彩色摄像头视角是不一样的,直接输出的高度图像与彩色图像的位置会对不上。如下图,高度摄像头的视野要比彩色摄像头的视野来的广。

intel realsense 深度相机深度图像处理API总结

所以,需要使用过滤器,对彩色图像或者深度图像进行处理,使两者在空间上进行对齐。对齐使用rs2::align过滤器

rs2::colorizer color_map(0);
rs2::align align_to_depth(RS2_STREAM_DEPTH);
rs2::align align_to_color(RS2_STREAM_COLOR);
frames = align_to_color.process(frames);
rs2::frame color_frame = frames.get_color_frame();
rs2::frame depth_frame = frames.get_depth_frame().apply_filter(color_map);
const int w = depth_frame.as<rs2::video_frame>().get_width();
const int h = depth_frame.as<rs2::video_frame>().get_height();

cv::Mat frame_color(cv::Size(w, h), CV_8UC3, (void*)color_frame.get_data(), cv::Mat::AUTO_STEP);
cv::Mat frame_depth(cv::Size(w, h), CV_8UC3, (void*)depth_frame.get_data(), cv::Mat::AUTO_STEP);

 cv::cvtColor(frame_color, frame_color, cv::COLOR_RGB2BGR);
 cv::cvtColor(frame_color, frame_color, cv::COLOR_RGB2BGR);

cv::imshow("color", frame_color);
cv::imshow("depth", frame_depth);
cv::waitKey(1);

intel realsense 深度相机深度图像处理API总结
intel realsense 深度相机深度图像处理API总结

3.其他过滤器使用方式

intel realsense 深度相机深度图像处理API总结

Original: https://blog.csdn.net/qq_30150579/article/details/127157697
Author: AoDeLuo
Title: intel realsense 深度相机深度图像处理API总结

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/633371/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球