Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save into .bag file pyrealsense2 #4057

Closed
filipematosinov opened this issue May 23, 2019 · 9 comments
Closed

Save into .bag file pyrealsense2 #4057

filipematosinov opened this issue May 23, 2019 · 9 comments

Comments

@filipematosinov
Copy link


Required Info
Camera Model { D400 }
Firmware Version (Open RealSense Viewer --> Click info)
Operating System & Version Linux (Ubuntu 18.04
Kernel Version (Linux Only) (e.g. 4.14.13)
Platform PC
SDK Version { legacy / 2.. }
Language {python}
Segment {Robot/Smartphone/VR/AR/others }

Issue Description

Hello,
I am wondering how is the best way to save a stream (color + depth) into a .bag using pyrealsense. I have seen several examples to read from a bag file but nothing to save. My particular application needs to save to streams (from two cameras) to two .bag files.

@realsens01
Copy link

Hi @filipematosinov ,

If I understand your question correctly, then you can do that by setting up config objects and passing them to the start function of the pipeline object. There is some example code in issue #3044. I am collecting data from two D435 cameras in this fashion. There are a number of issues to be aware of (such as the one that I linked).

@filipematosinov
Copy link
Author

Thank you @realsens01. I am now able to save them correctly. However, to read it how can I read it frame by frame (i.e not reading at the actual fps of the video) in order to preform some calculations to each frame which are slower than the actual fps.

@realsens01
Copy link

Some time ago, I tried doing this with the Realsense playback feature, but I had better luck with the rosbag python interface. Take a look at the rosbag wiki for examples. On Ubuntu, the relevant package for me was installed via apt install python3-rosbag. I wrote a Python class that basically pulls all of the information out of the bag using rosbag. Here's some code that illustrates the general idea:

import rosbag
bag    = rosbag.Bag('realsense.bag')
topics = ['/device_0/sensor_1/Color_0/image/data']
for message_data in bag.read_messages():
     (topic, msg, t) = message_data
     # Do something with the frame data in msg here.

This pulls out the color image stream. Leave out topics to process every type of ROS message, or change topics to include different streams.

However, I see posts on the forum that seem to indicate that there's been relevant developments in the Realsense API. Others on the forum might be able to give you a better idea about what is the most appropriate approach, at present. Hopefully, someone more knowledgeable will chime in.

@filipematosinov
Copy link
Author

Thanks for the advice @realsens01 :). Let's see if someone comes up with a high level realsense API approach. In the meantime I will have a look at tje python ROSBAG package, I was trying to avoid using ROS but maybe is better not to be scared!!

@filipematosinov
Copy link
Author

Moreover is it possible to save multiple cameras in the same bag? From your example it seems you can have several devices but using the pyrealsense API we have to call config (config.enable_record_to_file(...) ) which is created for each camera if I am correct

@realsens01
Copy link

My experience with the rosbag API has been far better than librealsense API. Admittedly, my experience is somewhat limited in both cases, but everything I tried worked as the documentation said it would. On the other hand, I've had problems with Realsense for months, and the documentation / support haven't been much help.

I do not believe that it is possible to save multiple cameras in the same bag with the Realsense API, but I am not certain. You are correct: I initialize and configure each of my two cameras separately, and they record to a pair of bag files.

@RealSenseCustomerSupport
Copy link
Collaborator


@filipematosinov Did you get it through now? Any other questions? Looking forward to your update. Thanks!

@RealSenseCustomerSupport
Copy link
Collaborator


@filipematosinov Just as realsens01 mentioned, currently saving multiple cameras in the same bag not supported. Any other questions about this ticket?

@RealSenseCustomerSupport
Copy link
Collaborator


@filipematosinov If no other questions about it, will close it accordingly. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants