环境:VS2017 + windows10 + opencv + librealsense2 + D435i
获取realsense IR图像
#include <iostream>
#include <opencv.hpp>
#include <librealsense2/rs.hpp>
int main()
{
int w = 1280;
int h = 720;
rs2::pipeline pipe;
rs2::config cfg;
cfg.enable_stream(RS2_STREAM_INFRARED, 1, w , h , RS2_FORMAT_Y8, 30);
pipe.start(cfg);
cv::namedWindow("InfraredWindow", cv::WINDOW_AUTOSIZE);
while (cv::waitKey(1) < 0)
{
rs2::frameset frames = pipe.wait_for_frames();
rs2::video_frame infrared = frames.get_infrared_frame();
cv::Mat infraredImage(cv::Size(w, h), CV_8UC1, (void*)infrared.get_data(), cv::Mat::AUTO_STEP);
cv::imshow("InfraredWindow", infraredImage);
}
return 0;
}
此时我们获取到的IR图像有很多的小白点,那我想要去掉这些小白点要怎么处理呢?
去除IR图像上的白点
#include <iostream>
#include <opencv.hpp>
#include <librealsense2/rs.hpp>
int main()
{
int w = 1280;
int h = 720;
rs2::pipeline pipe;
rs2::config cfg;
cfg.enable_stream(RS2_STREAM_INFRARED, 1, w , h , RS2_FORMAT_Y8, 30);
rs2::pipeline_profile selection = pipe.start(cfg);
auto depth_sensor = selection.get_device().first<rs2::depth_sensor>();
depth_sensor.set_option(RS2_OPTION_LASER_POWER, 15.0f); // 将这个参数值控制在 0 ~ 15.0f
cv::namedWindow("InfraredWindow", cv::WINDOW_AUTOSIZE);
while (cv::waitKey(1) < 0)
{
rs2::frameset frames = pipe.wait_for_frames();
rs2::video_frame infrared = frames.get_infrared_frame();
cv::Mat infraredImage(cv::Size(w, h), CV_8UC1, (void*)infrared.get_data(), cv::Mat::AUTO_STEP);
cv::imshow("InfraredWindow", infraredImage);
}
return 0;
}
此时获取到的IR图像是这样的
去掉白点后的获取深度图像问题
去掉前的深度图像:
去掉后的深度图像:
这里就有比较明显的问题,深度图像的质量有所下降,故而获取的深度信息会相对较差。