i want to get continuous distance frames from the intel realsense camera. so, i want to generate a Mat object (1 channel) with size 1280*720 (should be the resolution of the 415 realsense cam). this matrix should content only the distance information for every pixel.
In the examples of the realsense sdk you can find the file im-show which creates a Mat object, but this one is a BGR coded colored distance image.
You surely could convert this frame into HSV and getting the distance simply by the H channel. But, i think its not very clean solution to convert first the distance data into BGR, then into HSV and back into distance.
So, i made any changes on the example im-show:
#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
// not sure if all of these includes are needed:
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
// Declare RealSense pipeline, encapsulating the actual device and sensors
rs2::pipeline pipe;
// Start streaming with default recommended configuration
pipe.start();
const auto window_name = "Display Image";
namedWindow(window_name, WINDOW_AUTOSIZE);
while (waitKey(1) < 0 && getWindowProperty(window_name, WND_PROP_AUTOSIZE) >= 0)
{
rs2::frameset data = pipe.wait_for_frames(); // Wait for next set of frames from the camera
rs2::frame depth = data.get_depth_frame();
// Query frame size (width and height)
const int w = depth.as<rs2::video_frame>().get_width();
const int h = depth.as<rs2::video_frame>().get_height();
// Create OpenCV matrix of size (w,h) from the colorized depth data (bgr values)
Mat temp(Size(w, h), CV_8UC1, (void*)depth.get_data(), Mat::AUTO_STEP);
//Update the window with new data
imshow(window_name, temp);
}
return EXIT_SUCCESS;
}
i get no errors when compiling it, but the output data is really strange.
any ideas?