How to sync OAK-D cameras and save the IMU data with video frames

67 views Asked by At

I have 2 OAK-D Pro cameras and I need to sync them and save the MONO Camera "left or right" to video. I would like to get the IMU data for each frame or a 100 hz IMU output saved also.

Some code that records only the video and not IMU data is this:

from depthai_sdk import OakCamera, RecordType
import depthai as dai
from pathlib import Path
import csv
out_path = r"F:\CAMERAS"
OUTPUT_DIR = Path(out_path)
Output_csv = Path.joinpath(OUTPUT_DIR, "CSV")
print("Output", Output_csv)


def write_times(outime, big_array):
    print("Writing Timestamp CSV.")
    outname = outime.replace(":", "_") + ".csv"
    outfile = Path.joinpath(Output_csv, outname)
    header = ["Device", "Cam", "Timestamp"]
    with open(outfile,"w", newline='') as csvfile:
        spamwriter = csv.writer(csvfile, delimiter=',')
        spamwriter.writerow(header)
        for rowi in big_array:
            spamwriter.writerow(rowi)
        return True

device_infos = dai.Device.getAllAvailableDevices()
for device in device_infos:
    print(f"{device.mxid} {device.state}  Name {device.name} {device.platform}")

oakL =OakCamera("18443010A123AA0F00")

left = oakL.create_camera('left', resolution='720p', fps=20, encode='H265')
right = oakL.create_camera('right', resolution='720p', fps=20, encode='H265')

# Synchronize & save all (encoded) streams


oakR =OakCamera("1844301081B8AC0F00")
leftR = oakR.create_camera('left', resolution='720p', fps=20, encode='H265')
rightR = oakR.create_camera('right', resolution='720p', fps=20, encode='H265')
imuR = oakR.create_imu()

oakL.record([ left.out.encoded, right.out.encoded], out_path, RecordType.VIDEO)
oakR.record([ leftR.out.encoded, rightR.out.encoded], out_path, RecordType.VIDEO)
# Show left stream
oakL.visualize([left.out.camera], scale=2/3, fps=True)
#oakR.visualize([rightR.out.encoded], scale=2/3, fps=True)
oakL.start()
oakR.start()
left.control.set_exposure_iso(1500, 600) #setting either mono camera controls both
leftR.control.set_exposure_iso(1500, 600)

while oakL.running():

    key = oakL.poll()
    if key == ord('i'):
        left.control.exposure_time_down()
    elif key == ord('o'):
        left.control.exposure_time_up()
    elif key == ord('k'):
        left.control.sensitivity_down()
    elif key == ord('l'):
        left.control.sensitivity_up()
    elif key == ord('q'):
        oakL.close()
        oakR.close()
        break

    elif key == ord('e'): # Switch to auto exposure
        left.control.send_controls({'exposure': {'auto': True}})
print(f"Output folder {out_path}")
oakL.close()
oakR.close()

If I add IMU data and try to save it as MCAP, it fails with Module Not Found Error. No module named mcap_ros1. Is there a way to save the IMU data?

0

There are 0 answers