Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XLinkIn timestamps #932

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading