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)?
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
链接已复制
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
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,
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,
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).
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.
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
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?
