本页目录

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

多设备设置

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

发现OAK摄像头

您可以使用DepthAI发现所有连接的OAK摄像头,无论是通过USB还是局域网(OAK POE摄像头)。下面的代码片段会查找所有OAK摄像头并打印它们的DeviceIDs(唯一标识符)和XLink state
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# 指定设备ID、IP地址或USB路径
2device_info = depthai.DeviceInfo("14442C108144F1D000") # 设备ID
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

多摄像头标定

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

GitHub上的多摄像头标定

GitHub标志