Hi,
I'm trying to save videos and then save the depth maps frame by frame but I get errors with the devices
My codes work individually but when I put them together the recording works fine and then when I try to get the depth maps I get a "no available devices" error. I tried to close the device after recording so that it's available for saving the depth maps so I tried to call my function to record inside the
with dai.Device(pipeline) as device:
I get this error: record.start(), "pipeline already running"
What I would want is change this function
def run():
with contextlib.ExitStack() as stack:
# Record from all available devices
device_infos = dai.Device.getAllAvailableDevices()
if len(device_infos) == 0:
raise RuntimeError("No devices found!")
else:
print("Found", len(device_infos), "devices")
devices = []
# TODO: allow users to specify which available devices should record
for device_info in device_infos:
openvino_version = dai.OpenVINO.Version.VERSION_2021_4
device = stack.enter_context(dai.Device(openvino_version, device_info, usb2Mode=False))
# Create recording object for this device
recording = Record(save_path, device, args)
# Set recording configuration # TODO: add support for specifying resolution recording.setTimelapse(args.timelapse)
recording.setRecordStreams(args.save)
recording.setQuality(args.quality)
recording.setMcap(args.mcap)
devices.append(recording)
for recording in devices:
recording.start() # Start recording
timelapse = 0
def roundUp(value, divisibleBy: float):
return int(divisibleBy * math.ceil(value / divisibleBy))
# If H265, we want to start recording with the keyframe (default keyframe freq is 30 frames)
SKIP_FRAMES = roundUp(1.5* args.fps, 30 if args.quality == "LOW" else 1)
args.frame_cnt += SKIP_FRAMES
# Terminate app handler
quitEvent = threading.Event()
signal.signal(signal.SIGTERM, lambda *_args: quitEvent.set())
print("\nRecording started. Press 'Ctrl+C' to stop.")
while not quitEvent.is_set():
try:
for recording in devices:
if 0 < args.timelapse and time.time() - timelapse < args.timelapse:
continue
# Loop through device streams
for q in recording.queues:
new_msg = q['q'].tryGet()
if new_msg is not None:
q['msgs'].append(new_msg)
if checkSync(recording.queues, new_msg.getSequenceNum()):
# Wait for Auto focus/exposure/white-balance
recording.frameCntr += 1
if recording.frameCntr <= SKIP_FRAMES: # 1.5 sec
continue
# Timelapse
if 0 < args.timelapse: timelapse = time.time()
if args.frame_cnt == recording.frameCntr:
quitEvent.set()
frames = dict()
for stream in recording.queues:
frames[stream['name']] = stream['msgs'].pop(0)
recording.frame_q.put(frames)
time.sleep(0.001) # 1ms, avoid lazy looping
except KeyboardInterrupt:
break
print('') # For new line in terminal
for recording in devices:
recording.frame_q.put(None)
recording.process.join() # Terminate the process
print("All recordings have stopped successfuly. Exiting the app.")
it is from luxonis/depthai-experimentsblob/master/gen2-record-replay/record.py
what I would want is call this function in my other script after this line
with dai.Device(pipeline) as device:
if name == 'main':
run(device)
so that it doesn't search for available devices but rather takes the device that is already being used
is it possible?
Thank you in advance