IMU 和视频同步
IMU 和视频同步
类似示例:
演示
Command Line
1~/depthai-python/examples/Sync $ python3 imu_video_synced.py
2IMU 类型:BNO086,固件版本:3.9.7
3
4设备时间戳 imu:0:00:05.379914
5设备时间戳 video:0:00:05.385096
6四元数:i: -0.0549 j: -0.0335 k: 0.0018 real: 0.9979
7
8设备时间戳 imu:0:00:05.410274
9设备时间戳 video:0:00:05.418425
10四元数:i: -0.0549 j: -0.0334 k: 0.0018 real: 0.9979
11
12设备时间戳 imu:0:00:05.445439
13设备时间戳 video:0:00:05.451753
14四元数:i: -0.0548 j: -0.0334 k: 0.0018 real: 0.9979
15
16设备时间戳 imu:0:00:05.475084
17设备时间戳 video:0:00:05.485082
18四元数:i: -0.0547 j: -0.0334 k: 0.0018 real: 0.9979
19
20设备时间戳 imu:0:00:05.510046
21设备时间戳 video:0:00:05.518411
22四元数:i: -0.0546 j: -0.0334 k: 0.0018 real: 0.9979设置
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py源代码
Python
PythonGitHub
1import depthai as dai
2import numpy as np
3import cv2
4from datetime import timedelta
5
6device = dai.Device()
7
8imuType = device.getConnectedIMU()
9imuFirmwareVersion = device.getIMUFirmwareVersion()
10print(f"IMU type: {imuType}, firmware version: {imuFirmwareVersion}")
11
12if imuType != "BNO086":
13 print("Rotation vector output is supported only by BNO086!")
14 exit(0)
15
16pipeline = dai.Pipeline()
17
18color = pipeline.create(dai.node.ColorCamera)
19imu = pipeline.create(dai.node.IMU)
20sync = pipeline.create(dai.node.Sync)
21xoutImu = pipeline.create(dai.node.XLinkOut)
22xoutImu.setStreamName("imu")
23
24xoutGrp = pipeline.create(dai.node.XLinkOut)
25xoutGrp.setStreamName("xout")
26
27color.setCamera("color")
28
29imu.enableIMUSensor(dai.IMUSensor.ROTATION_VECTOR, 120)
30imu.setBatchReportThreshold(1)
31imu.setMaxBatchReports(10)
32
33sync.setSyncThreshold(timedelta(milliseconds=10))
34sync.setSyncAttempts(-1)
35
36color.video.link(sync.inputs["video"])
37imu.out.link(sync.inputs["imu"])
38
39sync.out.link(xoutGrp.input)
40
41
42with device:
43 device.startPipeline(pipeline)
44 groupQueue = device.getOutputQueue("xout", 3, True)
45 while True:
46 groupMessage = groupQueue.get()
47 imuMessage = groupMessage["imu"]
48 colorMessage = groupMessage["video"]
49 print()
50 print("Device timestamp imu: " + str(imuMessage.getTimestampDevice()))
51 print("Device timestamp video:" + str(colorMessage.getTimestampDevice()))
52 latestRotationVector = imuMessage.packets[-1].rotationVector
53 imuF = "{:.4f}"
54 print(f"Quaternion: i: {imuF.format(latestRotationVector.i)} j: {imuF.format(latestRotationVector.j)} "
55 f"k: {imuF.format(latestRotationVector.k)} real: {imuF.format(latestRotationVector.real)}")
56 print()
57 cv2.imshow("video", colorMessage.getCvFrame())
58 if cv2.waitKey(1) == ord("q"):
59 break工作原理
- 初始化 DepthAI 设备。
- 检查连接的 IMU 类型和固件版本。
- 创建一个管道并添加 ColorCamera 和 IMU 节点。
- 设置 Sync 节点以同步 IMU 数据和视频帧。
- 将 ColorCamera 和 IMU 节点的输出链接到 Sync 节点。
- 启动管道并持续接收同步数据。
- 显示视频帧并打印 IMU 旋转矢量数据,包括四元数值。
需要帮助?
请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。