How to get left and right IR images from D435
| Required Info | |
|---|---|
| Camera Model | { D400 } |
| Firmware Version | (Open RealSense Viewer --> Click info) |
| Operating System & Version | {Win (10) |
| Kernel Version (Linux Only) | (e.g. 4.14.13) |
| Platform | PC |
| SDK Version | 2.0 |
Issue Description
we can use intel realsense SDK 2.0 sample to capture Depth and RGB images, but we cannot find the API to get the raw left and right IR images from D435. So any suggestion to solve it?
Hi @anson2004110 , Please have a look at the API-How-To : Start Streaming Left and Right Infrared Imagers
Thanks for your reply, we found the API as followed, but we don't know how to capture left and right IR images at the same time. @zivsha
//Contruct a pipeline which abstracts the device
rs2::pipeline pipe;
//Create a configuration for configuring the pipeline with a non default profile
rs2::config cfg;
//Add desired streams to configuration
cfg.enable_stream(RS2_STREAM_INFRARED, 1280, 720, RS2_FORMAT_Y8, 30);
cfg.enable_stream(RS2_STREAM_DEPTH, 1280, 720, RS2_FORMAT_Z16, 30);
//Instruct pipeline to start streaming with the requested configuration
pipe.start(cfg);
// Camera warmup - dropping several first frames to let auto-exposure stabilize
rs2::frameset frames;
for (int i = 0; i < 30; i++)
{
//Wait for all configured streams to produce a frame
frames = pipe.wait_for_frames();
}
//Get each frame
rs2::frame ir_frame = frames.first(RS2_STREAM_INFRARED);
rs2::frame depth_frame = frames.get_depth_frame();
// Creating OpenCV matrix from IR image
Mat ir(Size(640, 480), CV_8UC1, (void*)ir_frame.get_data(), Mat::AUTO_STEP);
// Apply Histogram Equalization
equalizeHist(ir, ir);
applyColorMap(ir, ir, COLORMAP_JET);
// Display the image in GUI
namedWindow("Display Image", WINDOW_AUTOSIZE);
imshow("Display Image", ir);
waitKey(0);
Hi, In cases where there are multiple streams of the same type in one sensor, like the case where the depth sensor has IR left and IR Right, you need to specify the indices numbers of the streams you want, so to get Depth and 2 Infrareds you should:
cfg.enable_stream(RS2_STREAM_INFRARED, 1, 1280, 720, RS2_FORMAT_Y8, 30);
cfg.enable_stream(RS2_STREAM_INFRARED, 2, 1280, 720, RS2_FORMAT_Y8, 30);
cfg.enable_stream(RS2_STREAM_DEPTH, 1280, 720, RS2_FORMAT_Z16, 30);
To get the frames, you can't use frameset::first<> anymore. You can either iterate over the frameset, or use the new get_infrared(index) method (See PR #1122)
@zivsha thanks,do you know how to convert rs2::video_frame ir_frame to Opencv Mat?
Please see opencv RealSense samples
Thank you all, then the useful code was shown as followed, note that we also add function get_infrared_frame into the rs_frame.hpp (see https://github.com/IntelRealSense/librealsense/pull/1122/commits/c391aa3bdbfe3609e3854652eb4b14e134ab4721)
int main(int argc, char * argv[])
{
int width = 1280;
int height = 720;
int fps = 30;
rs2::config config;
config.enable_stream(RS2_STREAM_INFRARED, 1, width, height, RS2_FORMAT_Y8, fps);
config.enable_stream(RS2_STREAM_INFRARED, 2, width, height, RS2_FORMAT_Y8, fps);
// start pipeline
rs2::pipeline pipeline;
rs2::pipeline_profile pipeline_profile = pipeline.start(config);
while (1) // Application still alive?
{
// wait for frames and get frameset
rs2::frameset frameset = pipeline.wait_for_frames();
// get single infrared frame from frameset
//rs2::video_frame ir_frame = frameset.get_infrared_frame();
// get left and right infrared frames from frameset
rs2::video_frame ir_frame_left = frameset.get_infrared_frame(1);
rs2::video_frame ir_frame_right = frameset.get_infrared_frame(2);
cv::Mat dMat_left = cv::Mat(cv::Size(width, height), CV_8UC1, (void*)ir_frame_left.get_data());
cv::Mat dMat_right = cv::Mat(cv::Size(width, height), CV_8UC1, (void*)ir_frame_right.get_data());
cv::imshow("img_l", dMat_left);
cv::imshow("img_r", dMat_right);
char c = cv::waitKey(1);
if (c == 's')
{
}
else if (c == 'q')
break;
}
return EXIT_SUCCESS;
}
Hi, I know this post is closed but I still have a question about the IR image of the D435 or D435i. Is it possible to get the IR image of the left image without the dot patern? Do you think we could use this IR image to observe thermal leakage of a window for example (compared to an IR Flir camera)?
The only way to make the IR pattern disappear for the d435 is to turn off the projector.
In your second question, no this won’t detect heat. That is a different wavelength range, generally closer to 10000nm. The IR we use is 850nm and 940nm but which is invisible to humans but won’t detect heat. It is also commonly called “near IR”.
how to get left and right image using cv_bridge in ROS?
Hi, In cases where there are multiple streams of the same type in one sensor, like the case where the depth sensor has IR left and IR Right, you need to specify the indices numbers of the streams you want, so to get Depth and 2 Infrareds you should:
cfg.enable_stream(RS2_STREAM_INFRARED, 1, 1280, 720, RS2_FORMAT_Y8, 30); cfg.enable_stream(RS2_STREAM_INFRARED, 2, 1280, 720, RS2_FORMAT_Y8, 30); cfg.enable_stream(RS2_STREAM_DEPTH, 1280, 720, RS2_FORMAT_Z16, 30);
Why are the infrared imagers index-ed from 1 instead of 0? Also the Wiki is wrong.