Items with no label
3335 Discussions

Converting .bag video to .raw frames

ASriv7
New Contributor I
9,903 Views

Is there a way to convert a 30-second .bag video recording to .raw frames (not compressed formats like JPEG)?

If not, I was thinking of modifying (looping) the https://github.com/IntelRealSense/librealsense/tree/master/examples/save-to-disk save-to-disk example to get a bunch of .raw images for 30 seconds, but it only saves PNG and CSV. How do I modify it to store .raw (like RealSense Viewer's "save snapshot" button does)?

0 Kudos
1 Solution
ASriv7
New Contributor I
4,787 Views

I found this in the official SDK, which explains how to work with .bag in C++: https://github.com/IntelRealSense/librealsense/blob/master/src/media/readme.md# using-rs2config-with-rs2pipeline https://github.com/IntelRealSense/librealsense/blob/master/src/media/readme.md# using-rs2config-with-rs2pipeline

There is also this https://github.com/IntelRealSense/librealsense/issues/1705# issuecomment-393149384 official "convert" utility in the development branch. (See "http://preshing.com/20170511/how-to-build-a-cmake-based-project/ How to Build a CMake-Based Project".)

So, there are https://github.com/IntelRealSense/librealsense/issues/1919 frame drops and other issues with the RealSense pipeline method of reading bag files (which https://github.com/UnaNancyOwen/rs_bag2image rs_bag2image also uses). A surefire way of reading all the information in a bag file is to use the official http://www.ros.org/ ROS software. In MATLAB, you can use the https://www.mathworks.com/products/robotics.html Robotics System Toolbox to get the frames from a bag file as follows:

bag = rosbag('file.bag'); % Load the rosbag.

rosbag info 'file.bag';

 

% Displays information in the command window. Use bagInfo = rosbag('info', 'file.bag') to get the information as a structure in a script. See https://github.com/IntelRealSense/librealsense/blob/master/src/media/readme.md%23under-the-hood https://github.com/IntelRealSense/librealsense/blob/master/src/media/readme.md# under-the-hood for explanations.

bSel = select(bag, 'Topic', '/device_0/sensor_0/Infrared_1/image/data'); % Select a specific topic from the above information. It should end with /image/data if you want the frames.

msgs = readMessages(bSel); % Read all the messages (here, frames) in that topic as an nx1 cell array.

% Iterate through the cell array and read each frame.

 

for i = 1 : numel(msgs)

 

img = readImage(msgs{i});

 

% Do something with the frame (img).

 

end

View solution in original post

17 Replies
MartyG
Honored Contributor III
4,787 Views

Developer UnaNancyOwen has a RealSense tool to convert bag files to images. It can produce a raw 16 bit image if the '-s' depth scaling option is not specified.

https://github.com/UnaNancyOwen/rs_bag2image GitHub - UnaNancyOwen/rs_bag2image: Tool to convert bag files to image files for RealSense

0 Kudos
ASriv7
New Contributor I
4,787 Views

Oh, right, thank you! I had come across this, but I missed out the -s raw option.

0 Kudos
MartyG
Honored Contributor III
4,787 Views

How I read the instructions is that not putting -s makes that command false and so the produced image is raw.

0 Kudos
ASriv7
New Contributor I
4,787 Views

So, even with -s=false, the program gives JPG and PNG. Is there a way to get .raw-extension images, like RealSense Viewer snapshots give?

0 Kudos
MartyG
Honored Contributor III
4,787 Views

Have you tried not putting -s at all? It seems that the bag file path is the only instruction that you must add and the others are optional choices.

0 Kudos
ASriv7
New Contributor I
4,787 Views

Yes, it still gives JPG and PNG. I think the -s option is only for changing the depth visualization, not for generating .raw image files.

Is there another way to get .raw frames?

0 Kudos
MartyG
Honored Contributor III
4,787 Views

I checked the instructions again. Yes, you can put -s=false like you tried. So you were doing it ccorrectky.

I do not know of another way to produce a .raw file with RealSense, unfortunately.

0 Kudos
TsukasaSugiura
Beginner
4,787 Views

Hi RealSense Developers,

I'm Tsukasa Sugiura who developed https://github.com/UnaNancyOwen/rs_bag2image rs_bag2image.

I will explain about save option of depth image.

You can save depth images with 8-bits (scaled depth value in range 0-255) or 16-bits (raw depth value) by changing the -scaling option.

However, The depth image that displayed on window is always scaled in order to easily visible. It doesn't depend on the option.

Thease images are saved in PNG format. It is a common format on many platforms, and It can be read with many programs and tools.

In case of 16-bits (-scaling=false), It is 16-bits PNG format. Otherwise (-scaling=true, default), It is 8-bits PNG format.

The PNG format is lossless compression. If you choose -scaling=false, You can get real raw values by decoding these images.

Therefore, You can convert RAW format from 16-bits PNG format yourself.

(It is good to using exiting image processing tools or write simple scripts.)

Thanks,

---

2018/07/06

Sorry, It had a bug about save to 16-bits raw depth images.

I have fixed it and released a https://github.com/UnaNancyOwen/rs_bag2image/releases/tag/v0.1.3 new version.

Thanks,

0 Kudos
MartyG
Honored Contributor III
4,787 Views

Thanks so much for the information and link to rs_bag2image. And thank you greatly too for your documentation site and your OpenCV-compatible sample programs. Your contributions are invaluable to the RealSense community.

0 Kudos
TsukasaSugiura
Beginner
4,787 Views

Sorry, It had a bug about save to 16-bits raw depth images.

I have fixed it and released a https://github.com/UnaNancyOwen/rs_bag2image/releases/tag/v0.1.3 new version.

Thanks,

0 Kudos
ASriv7
New Contributor I
4,787 Views

I looked at the source code for the RealSense Viewer "save snapshot" button and used https://github.com/IntelRealSense/librealsense/blob/0fccea59fa7c7b6fef41359a242df02534ff1d24/common/model-views.cpp# L258 this function to save .raw frames while recording itself (i.e. I didn't record a .bag and then convert it).

0 Kudos
MartyG
Honored Contributor III
4,787 Views

Awesome news, thanks for the update about your success!

0 Kudos
TLamb
Beginner
4,787 Views

Hey guys, Im a beginner with the Real Sense technology.

How am I supposed to use this function ? Where to implement it ? Do you directly modify the source code of the Viewer ? How to do so ?

Thank you !

0 Kudos
MartyG
Honored Contributor III
4,787 Views

If you just want to capture a single frame as a PNG, the RealSense Viewer has built-in save and record. To capture a frame instead of recording a sequence of frames with the Record button, click on the Pause icon to pause the stream, and then click on the Snapshot button next to it to capture that paused frame as a PNG image.

Modifying the source code of the Viewer to add more complex functionality such as constant frame saving is more difficult. You would first have to set up a 'development environment' with a program script editing software package such as Visual Studio.

0 Kudos
ASriv7
New Contributor I
4,788 Views

I found this in the official SDK, which explains how to work with .bag in C++: https://github.com/IntelRealSense/librealsense/blob/master/src/media/readme.md# using-rs2config-with-rs2pipeline https://github.com/IntelRealSense/librealsense/blob/master/src/media/readme.md# using-rs2config-with-rs2pipeline

There is also this https://github.com/IntelRealSense/librealsense/issues/1705# issuecomment-393149384 official "convert" utility in the development branch. (See "http://preshing.com/20170511/how-to-build-a-cmake-based-project/ How to Build a CMake-Based Project".)

So, there are https://github.com/IntelRealSense/librealsense/issues/1919 frame drops and other issues with the RealSense pipeline method of reading bag files (which https://github.com/UnaNancyOwen/rs_bag2image rs_bag2image also uses). A surefire way of reading all the information in a bag file is to use the official http://www.ros.org/ ROS software. In MATLAB, you can use the https://www.mathworks.com/products/robotics.html Robotics System Toolbox to get the frames from a bag file as follows:

bag = rosbag('file.bag'); % Load the rosbag.

rosbag info 'file.bag';

 

% Displays information in the command window. Use bagInfo = rosbag('info', 'file.bag') to get the information as a structure in a script. See https://github.com/IntelRealSense/librealsense/blob/master/src/media/readme.md%23under-the-hood https://github.com/IntelRealSense/librealsense/blob/master/src/media/readme.md# under-the-hood for explanations.

bSel = select(bag, 'Topic', '/device_0/sensor_0/Infrared_1/image/data'); % Select a specific topic from the above information. It should end with /image/data if you want the frames.

msgs = readMessages(bSel); % Read all the messages (here, frames) in that topic as an nx1 cell array.

% Iterate through the cell array and read each frame.

 

for i = 1 : numel(msgs)

 

img = readImage(msgs{i});

 

% Do something with the frame (img).

 

end
ROhle
Novice
4,787 Views

in 2.12.0 the convert app does not produce a complete data set. IR2 is missing. Hopefully this is fixed in 2.13.

0 Kudos
SEich2
Beginner
4,787 Views

I am using the rs_bag2image tool to convert video from a D435. When I set -s=false I just get an 8-bit DNG containing only black or white pixels (0 or 255). The -s=true yields an 8-bit greyscale image. I'm using the May 8th build of the tool in a Windows 10 environment. Are other people having similar issues or experiencing success?

0 Kudos
Reply