1
votes

I have an Intel Lidar L515 and have recorded a ROS message through realsense-viewer with default settings on Windows.

I am interested in the depth message: /device_0/sensor_0/Depth_0/image/data.

I have subscribed to the ROS sensor_msg::Image topic in C++, and am converting to an opencv image using cv_bridge. I'm trying to use the opencv at function with char, and am getting a lot of 7's, and many values from 168-190. I'm focused on the light green square in the middle, which is at 1.28 meters. The most common hex value when my mouse moves over it in the realsense-viewer is 0x1410.

The specs say the image data is Z16, and the data represents distance from the sensor. I have an object at 1.28 meters and the range of the sensor is 9 meters, though I don't think I have values beyond 2.5 as I'm in a relatively small room.

A code example of what I'm doing is:

void callback( const sensor_msgs::ImageConstPtr &depthImage, cv::Point upperLeft, cv::Point lowerRight )
{
  cv::Mat depthImage_cv = ( cv_bridge::toCvCopy( depthImage, depthImage->encoding ) )->image;
  for(int row = upperLeft.x; row <= lowerRight.x; row++)
  {
     for(int column = upperLeft.y; column <= lowerRight.y; column++)
     {
        float depth = depthImage_cv.at<uchar>(row,column);           
        ROS_INFO_STREAM("Depth char value: " << depth);
     }
  }
}

Here is an example image in the realsense-viewer, which shows a 0-4 scale: enter image description here

I know what distance my object is. I want to know how to find what pixel value it should be at if it accurately detects that object. Any help or insight is appreciated!

1

1 Answers

0
votes

Here are the things I've found in case it helps someone else, though I still wasn't able to use opencv's at function to produce results, so if someone can answer that I'll accept their answer.

  • using realsense-viewer under the L500 Depth Sensor tab you can choose certain things for your device before recording. The default for Depth Units is 0.000250. I still don't have an exact mapping between that and pixels, as going to 256 there is no clear cut equation.

  • I tried with a different bag file looking at a specific small square in the depth image where I knew the returns and all values returned were 0 for all of the formats below, but when moving my mouse over the same data in the realsense-viewer it was telling me the distance I knew the object was at, so the data is there:

      cv::Scalar depth = depthImage_cv.at<uchar>(row,column);
      float d1 = depthImage_cv.at<uchar>(row,column);
      int16_t d2 = depthImage_cv.at<uchar>(row,column);
      uint16_t d3 = depthImage_cv.at<uchar>(row,column);
      float d4 = depthImage_cv.at<char>(row,column);
      int16_t d5 = depthImage_cv.at<char>(row,column);
      uint16_t d6 = depthImage_cv.at<char>(row,column);
      float d7 = depthImage_cv.at<float>(row,column);
      int16_t d8 = depthImage_cv.at<float>(row,column);
      uint16_t d9 = depthImage_cv.at<float>(row,column);
      float d10 = depthImage_cv.at<ushort>(row,column);
      int16_t d11 = depthImage_cv.at<ushort>(row,column);
      uint16_t d12 = depthImage_cv.at<ushort>(row,column);
    

Ultimately, I went to the librealsense git library. I found the following file useful for reading in a file and using some librealsense way of serialization that interpreted the depth, but was ultimately able to programmatically get the depth which is what I needed. Here is my implementation, which is largely the example from the librealsense library with a few tweaks so I got the data from a file rather than a device. Hopefully this helps someone.