librealsense icon indicating copy to clipboard operation
librealsense copied to clipboard

Can't get more than 15 frames

Open Alonmeytal opened this issue 8 years ago • 5 comments

Required Info
Camera Model D435
Firmware Version 05.08.13.00
Operating System & Version Win10 64bit 1709
Kernel Version (Linux Only) -
SDK Version 0.282.1

Running a simple loop to get a set amount of frames from the camera. The loop constantly stops after 15 frames with a RuntimeError. The code is as follows:

for i in range(FRAMES_TO_RECORD):
	# Start measuring
	start_time = time.time()
	frame = pipeline.wait_for_frames(5000)
	frames.append(frame)
	time_now = time.time()
	print '[{}] {}'.format(time_now, i)
	time_per_frame_recieve.append(time.time() - start_time)	

It fails to get another frame even if I set the timeout to 20,000ms.

However, the Realsense viewer doesn't experience that issue.

Alonmeytal avatar Dec 25 '17 15:12 Alonmeytal

Hi @Alonmeytal

This is happening because the script is saving frames inside a collection. At the moment, all frames are recycled and live within shared frame-pools. By default, we only allow for 16 frames to cycle in the system.

This is done to reduce allocation time (we just fetch frame from the pool) and to ensure there is no consistent resource leak (if frames are processed slower then the rate at which they arrive, you must implement some kind of throttling mechanism or the application will run out of memory very fast).

We do however acknowledge the requirement to be able to save unlimited number of frames (either for data-collection or in garbage-collected environments) and will enable it soon. For now, if you are building the library from source, you can build the development branch and replace option_range{ 0, 32, 1, 16 } with option_range{ 0, 32, 1, 0 } in source.cpp:41. After rebuilding (with -DBUILD_PYTHON_BINDINGS=true) the script should work.

dorodnic avatar Dec 25 '17 16:12 dorodnic

Thanks for elaborating, I’ll give it a try!

Alonmeytal avatar Dec 25 '17 18:12 Alonmeytal

Is there a workaround other than installing from source? I tried deallocating objects running gc in python, but none are helping.

tispratik avatar May 30 '19 00:05 tispratik

I solved this problem by closing the pipelines and starting them again.

guyoffe avatar May 10 '20 22:05 guyoffe

Hello, I have the same problem : I need to surpass 15 frames because I am using multiprocessing, I read the commentary of @dorodnic which is very interesting and which explains well the problem. However, I am not very good at programming, can you help me to solve this ? I put my fonction below for processing : I want to stock all the frames I want inside a process called "acquisition_frames" After that, I use this process inside a main fonction which get all the frames to disp the video flow

def acquisition_frames(framelist, lock):
    print("Acquisition des frames")
    pipeline, config, cfg, dev, colorizer = Camera().param()
    print(dev.get_info(rs.camera_info.serial_number))
    print(dev.get_info(rs.camera_info.name))
    print(dev.get_info(rs.camera_info.firmware_version))
    print(dev.get_info(rs.camera_info.product_id))
    print(dev.get_info(rs.camera_info.physical_port))
    
    lst = []
    
    k = 0
    while k < 15 :
        lock.acquire()
        try : 

            frames = pipeline.wait_for_frames()
            depth_frame = frames.get_depth_frame()
            color_frame = frames.get_color_frame()
            depth_image = np.asanyarray(depth_frame.get_data())
            color_image = np.asanyarray(color_frame.get_data())
            depth_colormap = np.asanyarray(colorizer.colorize(depth_frame).get_data())
            lst.append(depth_colormap)
        finally : 
            lock.release()    
            k = k + 1
    framelist.put(lst)

PierreLouisT avatar Jan 19 '22 13:01 PierreLouisT