OAK Visualizer
OAK Visualizer
imshow() 函数更灵活的替代方案,支持同时查看多个流和交互式控件。目前在 Chrome 浏览器中完全支持。请注意,Visualizer 可与 DepthAI API 配合使用,并兼容所有 OAK 设备。请注意,Visualizer 的所有功能仅在 Chrome 中可用。所有浏览器都应支持 RAW 流。编码流及其衍生功能仅在 Chrome 中支持,因为它们需要完整的 WebCodecs API 集,而目前只有 Chrome 提供高质量和高性能的实现。

入门
基本设置
要使用 Visualizer,您需要在 DepthAI 应用程序中创建一个 运行此代码后,请在浏览器中打开
RemoteConnection:Python
1import depthai as dai
2
3# 创建一个 RemoteConnection (Visualizer 服务器)
4visualizer = dai.RemoteConnection()
5
6# 创建 pipeline
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 # 构建并启动 pipeline
19 pipeline.start()
20
21 # 将 pipeline 图注册到 Visualizer 以便可视化
22 visualizer.registerPipeline(pipeline)
23
24 # 在 pipeline 运行时执行的主循环
25 while pipeline.isRunning():
26 # 检查 Visualizer 中的按键事件
27 if visualizer.waitKey(1) == ord('q'):
28 # 如果按下 'q',则停止 pipeline
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")