View my account

Save Raw DepthFrame in c#

Comments

9 comments

  • MartyG

    Hi Juan Diezyanguas  The link below discusses saving raw depth data with C#.

    https://github.com/IntelRealSense/librealsense/issues/4201

     

    The discussion in that link also provides a link to C# scripting for accessing the data without copying in an unsafe context.

    https://github.com/IntelRealSense/librealsense/blob/master/wrappers/csharp/Documentation/cookbook.md#unsafe-direct-access

     

    Another approach would be to save the depth data to a bag file.

    https://github.com/IntelRealSense/librealsense/issues/3142

     

    The bag file could then be played back and have data retrieved from it.

    https://github.com/IntelRealSense/librealsense/blob/development/wrappers/csharp/Documentation/cookbook.md#playback

     

    An alternative way to obtain what you require from the bag file would be to use the RealSense SDK's rs-convert tool to extract the bag file's frames and convert them to a suitable format that preserves depth information such as csv, .raw or .bin.

    https://github.com/IntelRealSense/librealsense/tree/master/tools/convert

     

    A pre-made executable version of rs-convert can be found in the RealSense SDK's set of tools and examples.

    0
    Comment actions Permalink
  • Juan Diezyanguas

    Thanks for your reply!

    The method that I have used in my example getDistance is a good way or not?

    With regards,

    0
    Comment actions Permalink
  • MartyG

    Yes, GetDistance() is a good way to get the real-world distance value.

    0
    Comment actions Permalink
  • Juan Diezyanguas

    Thanks for your reply!

    I'm trying to compare the results using CopyTo and GetDistance method and it seems that they are not producing the same matrix.

    I'm not sure if I'm obtaining the correct data from the copyed ushort array.

    Thanks for your help.

    private readonly int _width;
    private readonly int _height;
    private readonly float _depthScale;
    private readonly ushort[] _depthData;
    private float[,] _frameData;
    private float[,] _frameData2;

    public RawDepthFrameDto(DepthFrame frame)
    {
        _width = frame.Width;
        _height = frame.Height;
        _depthScale = frame.Sensor.DepthScale;
        _depthData = new ushort[_width * _height];
        frame.CopyTo(_depthData);
        _frameData = new float[_height, _width];
        _frameData2 = new float[_height, _width];
        FillRawDepth(frame);
        FillRawDepthFromCopy();
    }

    private void FillRawDepth(DepthFrame frame)
    {
        for(int row = 0; row < _height; row++)
        {
            for(int column = 0; column < _width; column++)
            {
                _frameData[row, column] = frame.GetDistance(column, row);
            }
        }
    }

    private void FillRawDepthFromCopy()
    {
        for (int row = 0; row < _height; row++)
        {
            for (int column = 0; column < _width; column++)
            {
              var idx = (row * _width) + column;
                _frameData2[row, column] = _depthData[idx] * _depthScale;
            }
        }
    }

     

    0
    Comment actions Permalink
  • MartyG

    If GetDistance() is not used then the real-world depth value in meters is calculated by multiplying the depth value by 0.001 (the default 'depth unit scale' of the D415 camera.  For example, if the raw 'pixel depth' uint16_t value is 6500 then 6500 x 0.001 = 6.5 (meters real world distance).

     

    With the GetDistance() instruction there is no need to multiply the depth value by the depth unit scale value as it is already taken care of automatically by the instruction.

    0
    Comment actions Permalink
  • Juan Diezyanguas

    Yes,

    I know that it's not neccesary to use both ways, but I have done the code in my previous post just to check that both matrix are equals using the multiply or the GetDistance() method.

    And it seems that they are not equal. That is the reason because I have posted it to show you the code and check if you see correct o detect any error.

    I think that it's better to use CopyTo() because it is much more faster to use the GeDistance() method arround all the image pixels.

    With regards,

     

    0
    Comment actions Permalink
  • MartyG

    If you know approximately what the correct depth value should be, which of the two methods (GetDistance or CopyTo) is more accurate?

    0
    Comment actions Permalink
  • Juan Diezyanguas

    Hi Mary,

    I think that I have solved it, I was accesing to not correct index of the ushot array. I have updated my code in my post.

    With regards,

    0
    Comment actions Permalink
  • MartyG

    That's great to hear that you achieved a solution.  Thanks very much for the update!

    0
    Comment actions Permalink

Please sign in to leave a comment.