Items with no label
3338 Discussions

streaming from bag files

EZann1
Novice
2,305 Views

Dear all,

I have some .bag files recorded from 415d using Intel Viewer.

I am using Matlab R2017a with the wrappers provided on the website to access the frame sets from file.

Since the I am doing several post-processing steps on each frame set, it turns out that I loose a lot of frames and I also loose the benefit of doing the analysis offline. Is there a way to pause and resume the streaming or to read one frame at a time?

Here below you can find my code, with which I try to do some offline processing on the first 100 frames. In reality, the code is too slow, so I get to the end of the file after about 30 iterations and then I start getting frames from the beginning of the file (as I can see from the timestamps).

 

Thank you in advance!

 

% Make Config object to manage pipeline settings

cfg = realsense.config();

% Tell pipeline to stream from the given rosbag file

cfg.enable_device_from_file('C:\Program Files (x86)\Intel RealSense SDK 2.0\matlab\test 18ml 1280x720.bag');

 

% Make Pipeline object to manage streaming

pipe = realsense.pipeline(); 

pointcloud = realsense.pointcloud();

% Start streaming from the rosbag

profile = pipe.start(cfg);

n = 100;

TS = zeros(1,n);

z = zeros(1,n);

for i=1:n  

% Get frame 

% Get streaming device's name

dev = profile.get_device();

serial_number = dev.get_info(realsense.camera_info.serial_number);

  fs = pipe.wait_for_frames();

  align_to = realsense.stream.color;

  alignedFs = realsense.align(align_to);  

  aligned_frames = alignedFs.process(fs);

  depth = aligned_frames.get_depth_frame();

  data1 = depth.get_data();

  pointcloud.map_to(depth);

  points = pointcloud.calculate(depth);

  vertices = points.get_vertices();

...

  TS(i) = fs.get_frame_metadata(9);

 

end

0 Kudos
1 Solution
MartyG
Honored Contributor III
1,828 Views

MATLAB has a built-in Pause function for pausing execution of a stream until a key is pressed.

 

https://uk.mathworks.com/help/matlab/ref/pause.html

 

Alternatively, if you want to handle the process within the RealSense SDK, the SDK has a function called Keep() that allows you to store the frames in memory and then do post-processing steps on all the frames at the end of the file. Because of the memory that is consumed by storing frames in memory though, it is best suited to short recording durations.

 

The link below has a Keep() script provided by Dorodnic the RealSense SDK Manager.

 

https://github.com/IntelRealSense/librealsense/issues/1942#issuecomment-400031901

 

Keep() is usually used with live-streaming data rather than pre-recorded bag files. A bag file is just basically a recording of the data from a live stream though, so I would speculate that Keep() may be applicable to a bag if the bag file is used as the data source for the pipeline.

 

In regard to approaching the problem by pausing and resuming frames using the SDK's playback functions (instead of the built-in pause function in MATLAB), the link below is very informative.

 

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

View solution in original post

0 Kudos
2 Replies
MartyG
Honored Contributor III
1,829 Views

MATLAB has a built-in Pause function for pausing execution of a stream until a key is pressed.

 

https://uk.mathworks.com/help/matlab/ref/pause.html

 

Alternatively, if you want to handle the process within the RealSense SDK, the SDK has a function called Keep() that allows you to store the frames in memory and then do post-processing steps on all the frames at the end of the file. Because of the memory that is consumed by storing frames in memory though, it is best suited to short recording durations.

 

The link below has a Keep() script provided by Dorodnic the RealSense SDK Manager.

 

https://github.com/IntelRealSense/librealsense/issues/1942#issuecomment-400031901

 

Keep() is usually used with live-streaming data rather than pre-recorded bag files. A bag file is just basically a recording of the data from a live stream though, so I would speculate that Keep() may be applicable to a bag if the bag file is used as the data source for the pipeline.

 

In regard to approaching the problem by pausing and resuming frames using the SDK's playback functions (instead of the built-in pause function in MATLAB), the link below is very informative.

 

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

0 Kudos
EZann1
Novice
1,828 Views

Thank you!

Has anyone had any luck using the matlab playback wrappers?

0 Kudos
Reply