Skip to content

Commit

Permalink
Merge branch 'xlinkin_timestamps' of github.com:luxonis/depthai-pytho…
Browse files Browse the repository at this point in the history
…n into bl_lock_bugix_devel
  • Loading branch information
asahtik committed Dec 8, 2023
2 parents a4c687e + aa7e8fb commit 1223d91
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
59 changes: 59 additions & 0 deletions examples/Sync/imu_video_synced.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1223d91

Please sign in to comment.