OAK Visualizer
最后更新
imshow() 函数更灵活的替代方案,支持同时查看多个流和交互式控制。目前它在 Chrome 浏览器中得到全面支持。请注意,Visualizer 适用于 DepthAI API,并与所有 OAK 设备兼容。请注意,Visualizer 的所有功能仅在 Chrome 中可用。所有浏览器都应支持 RAW 流。编码流和基于它们的功能仅在 Chrome 中受支持,因为它们需要完整的 WebCodecs API 集,目前只有 Chrome 提供了高质量和高性能的实现。
入门
Basic Setup
要使用 Visualizer,您需要在 DepthAI 应用程序中创建一个 运行此代码后,在浏览器中打开
RemoteConnection:Python
1import depthai as dai
2
3# 创建一个 RemoteConnection (Visualizer 服务器)
4visualizer = dai.RemoteConnection()
5
6# 创建管道
7with dai.Pipeline() as pipeline:
8 # 创建摄像头节点
9 # 不带参数的 build 方法将使用默认摄像头
10 rgb_cam = pipeline.create(dai.node.Camera).build()
11
12 # 从摄像头请求分辨率为 1280x720 的 NV12 流
13 rgb_stream = rgb_cam.requestOutput(size=(1280, 720), type=dai.ImgFrame.Type.NV12)
14
15 # 将摄像头流作为主题添加到 Visualizer
16 visualizer.addTopic("rgb", rgb_stream)
17
18 # 构建并启动管道
19 pipeline.start()
20
21 # 注册管道图以在 Visualizer 中可视化
22 visualizer.registerPipeline(pipeline)
23
24 # 管道运行时执行的主循环
25 while pipeline.isRunning():
26 # 检查 Visualizer 中的按键
27 if visualizer.waitKey(1) == ord('q'):
28 # 如果按下 'q',则停止管道
29 pipeline.stop()http://localhost:8080 以查看流。功能
- 多流查看 - 在浏览器中同时查看所有摄像头流
- 自定义消息队列 - 创建自定义消息队列以向 Visualizer 发送数据
- 远程查看 - 从网络上的任何设备访问 Visualizer
API 参考
RemoteConnection 类
RemoteConnection 类是 Visualizer 的主要接口:Python
1remote = dai.RemoteConnection(
2 address="0.0.0.0", # 要绑定的 IP 地址
3 webSocketPort=8765, # WebSocket 端口
4 serveFrontend=True, # 是否提供前端 UI
5 httpPort=8080 # Web 界面的 HTTP 端口
6)添加主题
Python
1remote.addTopic(
2 topicName="rgb", # 在 UI 中显示的名称
3 output=rgb_stream, # 要流式传输的节点输出
4 group="Cameras", # 可选组名
5 useVisualizationIfAvailable=True # 如果存在,将调用输出对象上的 getVisualizationMessage 方法以获取可视化效果。
6)Python
1rgb_queue = visualizer.addTopic(
2 topicName="rgb", # 在 UI 中显示的名称
3 group="Cameras", # 可选组名
4 maxSize=2, # 创建队列的最大大小
5 blocking=False, # 指示创建的队列是否会阻塞
6 useVisualizationIfAvailable=True # 如果存在,将调用输出对象上的 getVisualizationMessage 方法以获取可视化效果。
7)
8# 将自定义数据发送到队列
9rgb_queue.send(my_data)与神经网络集成
Python
1# 创建神经网络节点
2nn = pipeline.create(dai.node.DetectionNetwork).build(
3 input=rgb_cam, # 用作神经网络输入的摄像头节点
4 model="luxonis/yolov6-nano:r2-coco-512x288", # Luxonis Hub 中的模型 slug
5)
6nn.setConfidenceThreshold(0.5)
7
8# 将神经网络结果添加到 Visualizer
9remote.addTopic("detections", nn.out, group="RGB")示例应用程序
多摄像头流
Python
1# 创建摄像头
2rgb_cam = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
3left_cam = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
4right_cam = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)
5
6# 从摄像头请求 NV12 流
7rgb_stream = rgb_cam.requestOutput(size=(1280, 720), type=dai.ImgFrame.Type.NV12)
8left_stream = left_cam.requestOutput(size=(800, 600), type=dai.ImgFrame.Type.NV12)
9right_stream = right_cam.requestOutput(size=(1280, 720), type=dai.ImgFrame.Type.NV12)
10
11# ...
12
13# 将所有摄像头添加到 Visualizer
14remote.addTopic("rgb", rgb_stream, group="Cameras")
15remote.addTopic("left", left_stream, group="Cameras")
16remote.addTopic("right", right_stream, group="Cameras")对象检测可视化
Python
1# 设置检测网络
2nn = pipeline.create(dai.node.DetectionNetwork).build(
3 input=rgb_cam, # 用作神经网络输入的摄像头节点
4 model="luxonis/yolov6-nano:r2-coco-512x288", # Luxonis Hub 中的模型 slug
5)
6nn.setConfidenceThreshold(0.5)
7
8# 将 RGB 预览和检测添加到 Visualizer
9remote.addTopic("preview", rgb_stream, group="Camera")
10remote.addTopic("detections", nn.out, group="Camera")