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

I'm getting repeated frames when I try to read from a .bag file using pyrealsense2 #2411

Closed
alizarghami opened this issue Sep 18, 2018 · 5 comments
Assignees

Comments

@alizarghami
Copy link

  • Before opening a new issue, we wanted to provide you with some useful suggestions (Click "Preview" above for a better view):

  • All users are welcomed to report bugs, ask questions, suggest or request enhancements and generally feel free to open new issue, even if they haven't followed any of the suggestions above :)


Required Info
Camera Model D415
Operating System & Version Win 10
Platform PC
SDK Version 2..
Language python

Issue Description

Hello realsense community

I'm facing an issue with reading frames from bag files which I recorded using a D415 realsense camera which I'll try to explain it brief.

I'm using the following code:

pipeline = rs.pipeline()
cfg = rs.config()
cfg.enable_device_from_file(file_path)
profile = pipeline.start(cfg)

ts_list = []
fnum = 0

while True:

        # get frame from pipeline
    frames = pipeline.wait_for_frames() 
    
        # get frame timestamp
    ts = frames.get_timestamp()
         
        # get depth and color frames
    depth_frame = frames.get_depth_frame()
    color_frame = frames.get_color_frame()

        # Convert images to numpy arrays
    depth_image = np.asanyarray(depth_frame.get_data())
    color_image = np.asanyarray(color_frame.get_data())
  
        # Apply colormap on depth image (image must be converted to 8-bit per pixel first)
    depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)

        # create a depth matrix with size of rgb image
    depth_mx = depth2img(depth_frame)
        
        # define some tapes for patches 
    tape_y = [int(depth_mx.shape[0]/2) - 100, int(depth_mx.shape[0]/2) + 100]
    tape_x = [int(depth_mx.shape[1]/2) - 100, int(depth_mx.shape[1]/2) + 100]

        # define some patches to check existence of any object
    patch_center = depth_mx[tape_y[0]:tape_y[1], tape_x[0]:tape_x[1]]

        # define some conditions for frame selection
    cond = np.sum(patch_center) < 80000

        ## select and save frames
    if cond: ## center patch contains an object
        if not os.path.isdir('./selected_frames/'):
            os.mkdir('./selected_frames/')

        cv2.imwrite("./selected_frames/" + str(fnum) + "_" + str(ts) + "_rgb.jpg", color_image)
        np.save("./selected_frames/" + str(fnum) + "_depth_mx.npy", depth_mx)
        np.save("./selected_frames/" + str(fnum) + "_depth_colormap.npy", depth_colormap)
        print('frame num %d saved' % fnum)

    fnum += 1

The above code should read each frame from a .bag file (input_file) using pipeline, do some processing on the frame and save it if it meets some condition.

The issue is that my code gives me frames in wrong order. Also some frames are repeated many times in the output.

I can't figure out why is this happening and would be very thankful if someone can assist me with any solution.

@RealSense-Customer-Engineering
Copy link
Collaborator

[Realsense Customer Engineering Team Comment]
Hi @alizarghami,

Without some processing there, just read the bag and save the files, is the frame order correct?

@alizarghami
Copy link
Author

alizarghami commented Sep 20, 2018

Without some processing there, just read the bag and save the files, is the frame order correct?

Thanks for answering me.
I have done such an experiment. Among 5000 first frames that I get from the pipeline (without any processing), I get about 700 unique timestamps. which means I received about 4300 repeated frames.

@dorodnic
Copy link
Contributor

This is a known issue, planned to be resolved in the upcoming release (#2360)

@dorodnic
Copy link
Contributor

Should be resolved now in v2.16.1

@dorodnic
Copy link
Contributor

dorodnic commented Oct 8, 2018

Hopefully this can be resolved now
If you encounter more issues related to ROS recording, please open a new issue.

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

No branches or pull requests

3 participants