2

I am trying to process frames in a.bag file with realsense. Is there any way to extract all the frames from this bag file without dropping most of the frames. I could not find an answer online. Here is my code to read the bag file which is based on the Intel example:

import numpy as np
import pyrealsense2 as rs
import os
import time
import cv2

i = 0
try:
    config = rs.config()
    rs.config.enable_device_from_file(config, "test.bag", repeat_playback=False)
    pipeline = rs.pipeline()
    pipeline.start(config)

    while True:
        frames = pipeline.wait_for_frames()
        depth_frame = frames.get_depth_frame()
        if not depth_frame:
            continue
        depth_image = np.asanyarray(depth_frame.get_data())

        color_image = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)

        cv2.imwrite("D:/TEST/image/" + str(i) + ".png", color_image)
        i += 1
finally:
    pass
Waleed
  • 39
  • 3

1 Answers1

2

By default, the device plays back frames in real-time (similar to the live camera), so if you don't process them fast enough, some will be dropped. You can disable this behavior to get all of the frames one-by-one.

Something like this:

profile = pipeline.start(config)
playback=profile.get_device().as_playback() # get playback device
playback.set_real_time(False) # disable real-time playback
joshb
  • 5,182
  • 4
  • 41
  • 55