Items with no label
3335 Discussions

Looping through all pixels for depth is too slow

SMath17
Beginner
697 Views

Hi,

I am trying to save all the depth values in a frame. But if I loop through all pixels, it's too slow for 640 x 480.

I want to save all the depth values in a frame to a text file, but by the time it's done with first frame, we we already missed many many frames. How can I get around this? thanks

private void print_DepthFrameData(DepthFrame depth) { int skipPixels = 1; for (int i = 0; i < depth.Width; i += skipPixels) { for (int j = 0; j < depth.Height; j += skipPixels) { string frameNumber = depth.Number.ToString(); int pixelPointX = i; int pixelPointY = j; float distanceMM = depth.GetDistance(pixelPointX, pixelPointY); Console.WriteLine(frameNumber + " - " + "(" + pixelPointX + "," + pixelPointY + "): " + distanceMM); } } }

 

 

Capture.PNG

0 Kudos
1 Solution
MartyG
Honored Contributor III
294 Views

An SDK program called 'rs-depth' in the C language (not C++ or C#) prints a text-based representation of the depth image, This may give you some insights about approaches for optimizing your own script if you prefer to stick with that method. The script breaks the image into 10x5 pixel regions and approximates the coverage of pixels within one meter.

 

https://github.com/IntelRealSense/librealsense/tree/master/examples/C/depth

 

The most efficient way to record data is to save it into a 'bag' file. Other types of file saving, such as text or 'ply' point cloud data, may be considerably slower to record in real-time. The long discussion linked to below on the subject of file saving may be useful to you.

 

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

 

It includes a script provided by Dorodnic the RealSense SDK Manager to save raw depth data into a file as bytes.

 

https://github.com/IntelRealSense/librealsense/issues/1485#issuecomment-379703868

 

A bag file recording can also be converted outside of a program to a text file format called .csv that is suited to spreadsheets and databases. This can be done with a tool in the RealSense SDK called Convert.

 

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

View solution in original post

0 Kudos
3 Replies
MartyG
Honored Contributor III
295 Views

An SDK program called 'rs-depth' in the C language (not C++ or C#) prints a text-based representation of the depth image, This may give you some insights about approaches for optimizing your own script if you prefer to stick with that method. The script breaks the image into 10x5 pixel regions and approximates the coverage of pixels within one meter.

 

https://github.com/IntelRealSense/librealsense/tree/master/examples/C/depth

 

The most efficient way to record data is to save it into a 'bag' file. Other types of file saving, such as text or 'ply' point cloud data, may be considerably slower to record in real-time. The long discussion linked to below on the subject of file saving may be useful to you.

 

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

 

It includes a script provided by Dorodnic the RealSense SDK Manager to save raw depth data into a file as bytes.

 

https://github.com/IntelRealSense/librealsense/issues/1485#issuecomment-379703868

 

A bag file recording can also be converted outside of a program to a text file format called .csv that is suited to spreadsheets and databases. This can be done with a tool in the RealSense SDK called Convert.

 

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

0 Kudos
SMath17
Beginner
294 Views

First, thank you for all your help! I have seen you are very active in responding to everyone's posts.

 

Thanks for the info, I tried to create a .bag file and it was created successfully. But the file is too huge (for 1 min).

Is it possible to reduce the frequency of frames in .bag file? I only care about few fps, not many. Can this be configured?

Or is it possible to only record depth values in .bag file, not everything.

 

Thanks!

0 Kudos
MartyG
Honored Contributor III
294 Views

Thanks for your kind words!

 

I responded to your post on the GitHub.

 

https://github.com/IntelRealSense/librealsense/issues/3537?language=en_US#issuecomment-474578076

Reply