title: Extract depth frame from RealSense camera?
body: <p>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.</p>
  
  <p>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. </p>
  
  <p>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. </p>
  
  <p>So, i made any changes on the example im-show: </p>
  
  <pre><code>#include &lt;librealsense2/rs.hpp&gt; // Include RealSense Cross Platform API
  // not sure if all of these includes are needed: 
  #include "opencv2/imgproc.hpp"
  #include "opencv2/highgui.hpp"
  #include &lt;opencv2/core.hpp&gt;
  #include &lt;opencv2/imgcodecs.hpp&gt;
  #include &lt;iostream&gt;
  
  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) &lt; 0 &amp;&amp; getWindowProperty(window_name, WND_PROP_AUTOSIZE) &gt;= 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&lt;rs2::video_frame&gt;().get_width();
          const int h = depth.as&lt;rs2::video_frame&gt;().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;
  }
  </code></pre>
  
  <p>i get no errors when compiling it, but the output data is really strange. </p>
  
  <p><a href="https://i.stack.imgur.com/rAVPM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rAVPM.png" alt="enter image description here"></a></p>
  
  <p>any ideas?</p>