1 | initial version |
If what you want is to get an infrared image in CV_8U
, you have two options for me:
dev->enable_stream(rs::stream::infrared, 640, 480, rs::format::y8, 30);
just convert the native CV_16U
infrared image to the wanted format if you cannot change the stream for whatever reason (you need to scale to the destination range, otherwise the image is saturated):
Mat infrared_8U;
infrared.convertTo(infrared_8U, CV_8U, 1/256.0);
Supported formats for each RealSense camera can be found here. Getting started for the librealsense and OpenCV: https://github.com/IntelRealSense/librealsense/blob/master/doc/stepbystep/getting_started_with_openCV.md.
Demo code tested with an Intel SR300 camera:
// Create a context object. This object owns the handles to all connected realsense devices
rs::context ctx;
// Access the first available RealSense device
rs::device * dev = ctx.get_device(0);
// Configure Infrared stream to run at VGA resolution at 30 frames per second
dev->enable_stream(rs::stream::infrared, 640, 480, rs::format::y16, 30);
// Start streaming
dev->start();
// Camera warmup - Dropped several first frames to let auto-exposure stabilize
for(int i = 0; i < 30; i++) {
dev->wait_for_frames();
}
// Creating OpenCV Matrix from a color image
Mat infrared(Size(640, 480), CV_16U, (void*)dev->get_frame_data(rs::stream::infrared), Mat::AUTO_STEP);
Mat infrared_8U;
infrared.convertTo(infrared_8U, CV_8U, 1/256.0);
// Display in a GUI
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", infrared_8U);
waitKey(0);
2 | No.2 Revision |
If what you want is to get an infrared image in CV_8U
, you have two options for me:
dev->enable_stream(rs::stream::infrared, 640, 480, rs::format::y8, 30);
just convert the native CV_16U
infrared image to the wanted format if you cannot change the stream for whatever reason (you need to scale to the destination range, otherwise the image is saturated):
Mat infrared_8U;
infrared.convertTo(infrared_8U, CV_8U, 1/256.0);
1/255.0);
Supported formats for each RealSense camera can be found here. Getting started for the librealsense and OpenCV: https://github.com/IntelRealSense/librealsense/blob/master/doc/stepbystep/getting_started_with_openCV.md.
Demo code tested with an Intel SR300 camera:
// Create a context object. This object owns the handles to all connected realsense devices
rs::context ctx;
// Access the first available RealSense device
rs::device * dev = ctx.get_device(0);
// Configure Infrared stream to run at VGA resolution at 30 frames per second
dev->enable_stream(rs::stream::infrared, 640, 480, rs::format::y16, 30);
// Start streaming
dev->start();
// Camera warmup - Dropped several first frames to let auto-exposure stabilize
for(int i = 0; i < 30; i++) {
dev->wait_for_frames();
}
// Creating OpenCV Matrix from a color image
Mat infrared(Size(640, 480), CV_16U, (void*)dev->get_frame_data(rs::stream::infrared), Mat::AUTO_STEP);
Mat infrared_8U;
infrared.convertTo(infrared_8U, CV_8U, 1/256.0);
// Display in a GUI
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", infrared_8U);
waitKey(0);
3 | No.3 Revision |
If what you want is to get an infrared image in CV_8U
, you have two options for me:
dev->enable_stream(rs::stream::infrared, 640, 480, rs::format::y8, 30);
just convert the native CV_16U
infrared image to the wanted format if you cannot change the stream for whatever reason (you need to scale to the destination range, otherwise the image is saturated):
Mat infrared_8U;
infrared.convertTo(infrared_8U, CV_8U, 1/255.0);
1/256.0);
Supported formats for each RealSense camera can be found here. Getting started for the librealsense and OpenCV: https://github.com/IntelRealSense/librealsense/blob/master/doc/stepbystep/getting_started_with_openCV.md.
Demo code tested with an Intel SR300 camera:
// Create a context object. This object owns the handles to all connected realsense devices
rs::context ctx;
// Access the first available RealSense device
rs::device * dev = ctx.get_device(0);
// Configure Infrared stream to run at VGA resolution at 30 frames per second
dev->enable_stream(rs::stream::infrared, 640, 480, rs::format::y16, 30);
// Start streaming
dev->start();
// Camera warmup - Dropped several first frames to let auto-exposure stabilize
for(int i = 0; i < 30; i++) {
dev->wait_for_frames();
}
// Creating OpenCV Matrix from a color image
Mat infrared(Size(640, 480), CV_16U, (void*)dev->get_frame_data(rs::stream::infrared), Mat::AUTO_STEP);
Mat infrared_8U;
infrared.convertTo(infrared_8U, CV_8U, 1/256.0);
// Display in a GUI
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", infrared_8U);
waitKey(0);
4 | No.4 Revision |
If what you want is to get an infrared image in CV_8U
, you have two options for me:
dev->enable_stream(rs::stream::infrared, 640, 480, rs::format::y8, 30);
just convert the native CV_16U
infrared image to the wanted format if you cannot change the stream for whatever reason (you need to scale to the destination range, otherwise the image is saturated):
Mat infrared_8U;
infrared.convertTo(infrared_8U, CV_8U, 1/256.0);
You can also directly shift the bits:
Mat infrared_8U(infrared.size(), CV_8U);
for (int i = 0 ;i < infrared_8U.rows; i++) {
for (int j = 0; j < infrared_8U.cols; j++) {
infrared_8U.at<uchar>(i,j) = infrared.at<ushort>(i,j) >> 8;
}
}
Supported formats for each RealSense camera can be found here. Getting started for the librealsense and OpenCV: https://github.com/IntelRealSense/librealsense/blob/master/doc/stepbystep/getting_started_with_openCV.md.
Demo code tested with an Intel SR300 camera:
// Create a context object. This object owns the handles to all connected realsense devices
rs::context ctx;
// Access the first available RealSense device
rs::device * dev = ctx.get_device(0);
// Configure Infrared stream to run at VGA resolution at 30 frames per second
dev->enable_stream(rs::stream::infrared, 640, 480, rs::format::y16, 30);
// Start streaming
dev->start();
// Camera warmup - Dropped several first frames to let auto-exposure stabilize
for(int i = 0; i < 30; i++) {
dev->wait_for_frames();
}
// Creating OpenCV Matrix from a color image
Mat infrared(Size(640, 480), CV_16U, (void*)dev->get_frame_data(rs::stream::infrared), Mat::AUTO_STEP);
Mat infrared_8U;
infrared.convertTo(infrared_8U, CV_8U, 1/256.0);
// Display in a GUI
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", infrared_8U);
waitKey(0);
5 | No.5 Revision |
If what you want is to get an infrared image in CV_8U
, you have two options for me:
dev->enable_stream(rs::stream::infrared, 640, 480, rs::format::y8, 30);
just convert the native CV_16U
infrared image to the wanted format if you cannot change the stream for whatever reason (you need to scale to the destination range, otherwise the image is saturated):
Mat infrared_8U;
infrared.convertTo(infrared_8U, CV_8U, 1/256.0);
You can also directly shift the bits:
Mat infrared_8U(infrared.size(), CV_8U);
for (int i = 0 ;i < infrared_8U.rows; i++) {
for (int j = 0; j < infrared_8U.cols; j++) {
infrared_8U.at<uchar>(i,j) = infrared.at<ushort>(i,j) >> 8;
}
}
Not sure what happens if you write a CV_16U
image on disk as you seem to do.
Supported formats for each RealSense camera can be found here. Getting started for the librealsense and OpenCV: https://github.com/IntelRealSense/librealsense/blob/master/doc/stepbystep/getting_started_with_openCV.md.
Demo code tested with an Intel SR300 camera:
// Create a context object. This object owns the handles to all connected realsense devices
rs::context ctx;
// Access the first available RealSense device
rs::device * dev = ctx.get_device(0);
// Configure Infrared stream to run at VGA resolution at 30 frames per second
dev->enable_stream(rs::stream::infrared, 640, 480, rs::format::y16, 30);
// Start streaming
dev->start();
// Camera warmup - Dropped several first frames to let auto-exposure stabilize
for(int i = 0; i < 30; i++) {
dev->wait_for_frames();
}
// Creating OpenCV Matrix from a color image
Mat infrared(Size(640, 480), CV_16U, (void*)dev->get_frame_data(rs::stream::infrared), Mat::AUTO_STEP);
Mat infrared_8U;
infrared.convertTo(infrared_8U, CV_8U, 1/256.0);
// Display in a GUI
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", infrared_8U);
waitKey(0);