diff --git a/depthai-core b/depthai-core index 0cae1b073..7930da4ea 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 0cae1b0731568a788041fe423aaaa40a7162e74c +Subproject commit 7930da4ea455f1fa82e768f4ede581bafd10d9a8 diff --git a/examples/Sync/imu_video_synced.py b/examples/Sync/imu_video_synced.py new file mode 100644 index 000000000..7fbede660 --- /dev/null +++ b/examples/Sync/imu_video_synced.py @@ -0,0 +1,59 @@ +import depthai as dai +import numpy as np +import cv2 +from datetime import timedelta + +device = dai.Device() + +imuType = device.getConnectedIMU() +imuFirmwareVersion = device.getIMUFirmwareVersion() +print(f"IMU type: {imuType}, firmware version: {imuFirmwareVersion}") + +if imuType != "BNO086": + print("Rotation vector output is supported only by BNO086!") + exit(0) + +pipeline = dai.Pipeline() + +color = pipeline.create(dai.node.ColorCamera) +imu = pipeline.create(dai.node.IMU) +sync = pipeline.create(dai.node.Sync) +xoutImu = pipeline.create(dai.node.XLinkOut) +xoutImu.setStreamName("imu") + +xoutGrp = pipeline.create(dai.node.XLinkOut) +xoutGrp.setStreamName("xout") + +color.setCamera("color") + +imu.enableIMUSensor(dai.IMUSensor.ROTATION_VECTOR, 120) +imu.setBatchReportThreshold(1) +imu.setMaxBatchReports(10) + +sync.setSyncThreshold(timedelta(milliseconds=10)) +sync.setSyncAttempts(-1) + +color.video.link(sync.inputs["video"]) +imu.out.link(sync.inputs["imu"]) + +sync.out.link(xoutGrp.input) + + +with device: + device.startPipeline(pipeline) + groupQueue = device.getOutputQueue("xout", 3, True) + while True: + groupMessage = groupQueue.get() + imuMessage = groupMessage["imu"] + colorMessage = groupMessage["video"] + print() + print("Device timestamp imu: " + str(imuMessage.getTimestampDevice())) + print("Device timestamp video:" + str(colorMessage.getTimestampDevice())) + latestRotationVector = imuMessage.packets[-1].rotationVector + imuF = "{:.4f}" + print(f"Quaternion: i: {imuF.format(latestRotationVector.i)} j: {imuF.format(latestRotationVector.j)} " + f"k: {imuF.format(latestRotationVector.k)} real: {imuF.format(latestRotationVector.real)}") + print() + cv2.imshow("video", colorMessage.getCvFrame()) + if cv2.waitKey(1) == ord("q"): + break