Items with no label
3335 Discussions

C# D435 Record and Playback dept and color streams from rosbag structure

MCC001
Novice
1,441 Views

I can successfully record and playback color and depth frames using the samples provided. However I need to go a step further and access individual frames - select the ones i want and then export them as pointclouds etc.. But I'm facing a bit of inconsistency when replaying the frames using the sample provided.

 

So this is for about a 10 seconds recording.

When I set playback.Realtime to true the number of frames (framecount variable below) was 187 - which seems less. At 30 hz, shouldnt the count be roughly around 300 ?

 

Then when I set the playback.Realtime to false. While playing back the frame count comes 781 for a 10 second file - which seems way more now. ( Possibly my code is recounting the same frame but you could print out in the individual frame numbers to confirm )

 

With this command pipeline.Pollforframes() - should i expect it to be deterministic at all ?

 

So then how do we determine the playback has finished and the program should exit the loop ?

How do we know the exact number of frames recorded in rosbag structure ?

 

See the code below:

 

var t2 = Task.Run(async () =>

{   

  using (playback = PlaybackDevice.FromDevice(dev))

  {

    Debug.WriteLine(playback.FileName);

    playback.Realtime = false;

     

    int framecount = 0;

    var tspanDuration = ToTimeSpan(playback.Duration);

    while (playback.Status != PlaybackStatus.Stopped)

    {

      if (pbpipeline.PollForFrames(out FrameSet frames))

        using (frames)

        {

          var tspan = ToTimeSpan(playback.Position);

          framecount++;

          if (tspan.TotalMilliseconds == tspanDuration.TotalMilliseconds)

          {

            Trace.WriteLine("End of file reached ..-" + " framecount = " + framecount);

            framecount = 0;

            playback.Stop();

          }

 

          block.Process(frames); // this block defined elsewhere in retrieves frames and displays on User interface (wpf) 

        }

      await Task.Delay(30);

    }

    Debug.WriteLine("FrameCount = " + framecount);

    Debug.WriteLine("Done");     

  }

  Debug.WriteLine("**Playback Stopped**");

});

 

 

 

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

It is not unusual for the actual number of frames that you get from a recording to differ from what the ideal theoretical value should be, since frames can get 'dropped' during recording. A common cause of this is that the computing hardware being used for the recording cannot keep up with the load being placed on it by the recording, especially when recording at a high resolution.

 

Examples of causes for hardware bottlenecks are a processor that has some incompatibility with the compression algorithm (in which case turning off compression during recording may help), or a slow storage medium such as a non-SSD hard drive.

 

As your recording duration is only 10 seconds, a method that may help is to use a function called Keep() that enables you to record the frames to memory instead of to a file, and then do post-processing and save all the data to a file in one action if you wish. The link below may be useful to you.

 

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

 

The link below provides guidance regarding your question about accessing individual frames:

 

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

 

In the record and playback documentation, an example playback script uses a For loop to poll for frames and then close the stream when all the frames have been looped through.

 

https://github.com/IntelRealSense/librealsense/blob/master/src/media/readme.md#using-rs2config-with-rs2pipeline

 

******

 

If you have need to ask further questions in future, I should also bring the following message to your attention.

 

**********

 

As of June 10, 2019, Intel® RealSense™ product support has moved to https://support.intelrealsense.com. All new community posts must be submitted at https://support.intelrealsense.com. If you have existing threads on this Forum that were opened before June 10, 2019 and are not resolved, please re-post your question at https://support.intelrealsense.com. This Forum will continue to be searchable after the cutover.

 

You will still be able to create questions on this forum but those questions will not receive support from Intel. If you desire Intel support, please go to https://support.intelrealsense.com.

MCC001
Novice
1,227 Views

Thanks Marty ! I'll have a look at the links you have recommended. cheers

0 Kudos
Reply