Wednesday, January 5, 2022

[SOLVED] Capture data from intel realsense cameras pre-trigger

Issue

I'm hoping someone may be able to give me a suggestion or two to try...

Im using Raspberry PI 4 and intel RealSense D455. I have an external trigger(button) and I would like to record (for example) 5 seconds before the trigger event and save it into memory (ring buffer). Is there a way to do this with python and Intel RealSense camera. I know picamera has this option: https://picamera.readthedocs.io/en/latest/recipes1.html#circular-record1

I will be thankful for any advice.

Many thanks, Nejc


Solution

A ring buffer sounds similar to a double ended queue or deque.

I haven't used your camera, but what you could do is constantly record small intervals in a separate thread and append them to a deque. Once the trigger is activated, simply save the current state of the deque.

from collections import deque

clip_length = 0.1 # 100 milliseconds
save_length = 5 # seconds
buffer_length = save_length / clip_length    

buffer = deque(maxlen=buffer_length)

while True:
    clip = #record 100ms of video
    buffer.append(clip)
    


Answered By - Teejay Bruno