librealsense icon indicating copy to clipboard operation
librealsense copied to clipboard

RuntimeError: Frame did't arrive within 5000

Open chenzy777 opened this issue 5 years ago • 3 comments


Required Info
Camera Model D455
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

Issue Description

Several days ago, I ran the following script successfully. But today I always get this problem. Interestingly, When I unplug and replug the USB plugin, it work again. It happens the same way every time!

import numpy as np                        # fundamental package for scientific computing
import matplotlib.pyplot as plt           # 2D plotting library producing publication quality figures
import pyrealsense2 as rs                 # Intel RealSense cross-platform open-source API

import numpy as np

print("Environment Ready")

def export (mesh=False, pc=True):
    # Setup:
    pipe = rs.pipeline()
    cfg = rs.config()
    cfg.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
    # cfg.enable_stream(rs.stream.depth, 848, 480, rs.format.z16, 30)
    cfg.enable_stream(rs.stream.color, 640, 480, rs.format.rgb8, 30)
    profile = pipe.start(cfg)

    # Create an align object
    # rs.align allows us to perform alignment of depth frames to others frames
    # The "align_to" is the stream type to which we plan to align depth frames.
    align_to = rs.stream.color
    align = rs.align(align_to)

    # Skip 5 first frames to give the Auto-Exposure time to adjust
    for x in range(5):
        pipe.wait_for_frames()

    frames = []
    for x in range(15):
        frameset = pipe.wait_for_frames()
        aligned_frames = align.process(frameset)
        frames.append(aligned_frames.get_depth_frame())
        frames.append(aligned_frames.get_color_frame())

    # Cleanup:
    pipe.stop()
    print("Frames Captured")

    ##DECLARE FILTERS
    #Threshold filter
    threshold = rs.threshold_filter(min_dist = 0.15, max_dist = 2)
    #Decimation filter
    decimation = rs.decimation_filter()
    decimation.set_option(rs.option.filter_magnitude, 2)
    #Spatial filter
    spatial = rs.spatial_filter()
    spatial.set_option(rs.option.filter_magnitude, 1)#Filtering itterations from 1.000 to 5.000
    spatial.set_option(rs.option.filter_smooth_alpha, 1)
    spatial.set_option(rs.option.filter_smooth_delta, 3)# 8 is good
    spatial.set_option(rs.option.holes_fill, 2)
    #Temporal Filter
    temporal = rs.temporal_filter()
    temporal.set_option(rs.option.filter_smooth_alpha, 0.2)
    temporal.set_option(rs.option.filter_smooth_delta, 100)
    #Hole filling
    hole_filling = rs.hole_filling_filter()
    #Colorize
    colorizer = rs.colorizer()
    colorizer.set_option(rs.option.color_scheme, 2)
    rs.disparity_transform(True)
    rs.disparity_transform(True)

    #Apply filters
    for i in range(15):
        depth_frame = frames[i]
        depth_frame = threshold.process(depth_frame)
        depth_frame = temporal.process(depth_frame)
        depth_frame = decimation.process(depth_frame)
        depth_frame = spatial.process(depth_frame)
    
    # Create save_to_ply object
    ply = rs.save_to_ply("C://pc.ply")

    # Set options to the desired values
    # Generate a textual PLY with normals (mesh is already created by default)
    ply.set_option(rs.save_to_ply.option_ply_mesh, False)
    ply.set_option(rs.save_to_ply.option_ply_binary, False)
    ply.set_option(rs.save_to_ply.option_ply_normals, True)
    ply.set_option(rs.save_to_ply.option_ignore_color, False)

    print("Saving ply...")
    # Apply the processing block to the frameset which contains the depth frame and the texture
    ply.process(depth_frame)
    print("Done")

export()

chenzy777 avatar Feb 25 '21 02:02 chenzy777

Hi @Steven-ZY Does your script's start-up success improve if you add a hardware_reset() instruction to it like the example Python code in the link below, please?

https://github.com/IntelRealSense/librealsense/issues/3329#issuecomment-475293475

MartyG-RealSense avatar Feb 25 '21 11:02 MartyG-RealSense

Hi @Steven-ZY Do you require further assistance with this case, please? Thanks!

MartyG-RealSense avatar Mar 04 '21 07:03 MartyG-RealSense

Case closed due to no further comments received.

MartyG-RealSense avatar Mar 10 '21 07:03 MartyG-RealSense