此页面由 AI 自动翻译。查看英文原版

本页目录

  • 发现 OAK 摄像头
  • 选择要使用的特定 DepthAI 设备
  • 指定要使用的 POE 设备
  • 时间戳同步
  • 多摄像头演示
  • 多摄像头校准

多设备设置

您可以在此处找到 演示脚本。了解如何发现连接到您系统的多个 OAK 摄像头,并单独使用它们。
多摄像头演示

发现 OAK 摄像头

您可以使用 DepthAI 来发现所有连接的 OAK 摄像头,无论是通过 USB 还是通过局域网(OAK POE 摄像头)。下面的代码片段会查找所有 OAK 摄像头并打印它们的 DeviceID(唯一标识符)和 XLink 状态
Python
1import depthai
2for device in depthai.Device.getAllAvailableDevices():
3    print(f"{device.getDeviceId()} {device.state}")
系统中 3 个 DepthAI 的示例结果:
Command Line
114442C10D13EABCE00 XLinkDeviceState.X_LINK_UNBOOTED
214442C1071659ACD00 XLinkDeviceState.X_LINK_UNBOOTED
33604808376 XLinkDeviceState.X_LINK_GATE

选择要使用的特定 DepthAI 设备

从上面的检测到的设备中,使用以下代码选择您想在管道中使用的设备。例如,如果您想使用上面的第一个设备,请使用以下代码:
Python
1# 指定 DeviceID、IP 地址或 USB 路径
2device_info = depthai.DeviceInfo("14442C108144F1D000") # DeviceID
3#device_info = depthai.DeviceInfo("192.168.1.44") # IP 地址
4#device_info = depthai.DeviceInfo("3.3.3") # USB 端口名称
5with depthai.Device(device_info) as device:
6    # ...
您可以将此代码作为您自己用例的基础,以便在不同的 OAK 模型上运行不同的神经网络模型。

指定要使用的 POE 设备

您还可以通过 IP 地址指定要使用的 POE 设备,如上面的代码片段所示。现在,根据需要使用任意数量的 OAK 摄像头!由于 DepthAI 负责所有繁重的工作,您通常可以使用相当多的摄像头,而对主机的负担却很小。

时间戳同步

时间戳同步,也称为消息同步,涉及对来自各种传感器(包括帧、IMU 数据包、ToF 数据等)的消息进行对齐。有关时间戳同步的更多信息,请参阅 帧同步页面

多摄像头演示

Python
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5import contextlib
6
7def createPipeline(pipeline):
8    camRgb = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
9    output = camRgb.requestOutput((1280, 800), dai.ImgFrame.Type.NV12 ,dai.ImgResizeMode.CROP, 20).createOutputQueue()
10    return pipeline, output
11
12with contextlib.ExitStack() as stack:
13    deviceInfos = dai.Device.getAllAvailableDevices()
14    print("=== Found devices: ", deviceInfos)
15    queues = []
16    pipelines = []
17
18    for deviceInfo in deviceInfos:
19        pipeline = stack.enter_context(dai.Pipeline())
20        device = pipeline.getDefaultDevice()
21        
22        print("===Connected to ", deviceInfo.getDeviceId())
23        mxId = device.getDeviceId()
24        cameras = device.getConnectedCameras()
25        usbSpeed = device.getUsbSpeed()
26        eepromData = device.readCalibration2().getEepromData()
27        print("   >>> Device ID:", mxId)
28        print("   >>> Num of cameras:", len(cameras))
29        if eepromData.boardName != "":
30            print("   >>> Board name:", eepromData.boardName)
31        if eepromData.productName != "":
32            print("   >>> Product name:", eepromData.productName)
33        
34        pipeline, output = createPipeline(pipeline)
35        pipeline.start()
36        pipelines.append(pipeline)
37
38        queues.append(output)
39
40    while True:
41        for i, stream in enumerate(queues):
42            videoIn = stream.get()
43            assert isinstance(videoIn, dai.ImgFrame)
44            cv2.imshow(f"video_device{i}", videoIn.getCvFrame())
45        if cv2.waitKey(1) == ord('q'):
46            break

多摄像头校准

本示例演示了如何计算多个摄像头的外部参数(摄像机姿态)。它提供了确定多摄像头设置中不同摄像头相对位置和方向的实际示例。通过准确估计外部参数,我们可以确保每个摄像头捕获的图像正确对齐,并可以有效地组合以进行进一步的处理和分析。

Multiple camera calibration on GitHub

GitHub logo