HostDisplay 节点,通过 OpenCV 在设备上显示捕获的帧。HostDisplay 节点是 一个自定义主机节点,它从 DepthAI 管道接收图像帧,并使用 OpenCV 的 imshow 函数在主机上显示它们。该示例是手动调用管道队列的 .get() 方法以检索帧并使用 OpenCV 显示它们的替代方案。相反,HostDisplay 节点处理帧检索和显示过程,从而更轻松地可视化管道的输出。它是自定义主机节点最基本的示例。此示例需要 DepthAI v3 API,请参阅 安装说明。管道
源代码
Python
PythonGitHub
1import depthai as dai
2import cv2
3
4
5class HostDisplay(dai.node.HostNode):
6 def build(self, frameOutput: dai.Node.Output):
7 self.link_args(frameOutput) # Has to match the inputs to the `process` method
8
9 # This sends all the processing to the pipeline where it's executed by the `pipeline.runTasks()` or implicitly by `pipeline.run()` method.
10 # It's needed as the GUI window needs to be updated in the main thread, and the `process` method is by default called in a separate thread.
11 self.sendProcessingToPipeline(True)
12 return self
13
14 def process(self, message: dai.ImgFrame):
15 cv2.imshow("HostDisplay", message.getCvFrame())
16 key = cv2.waitKey(1)
17 if key == ord('q'):
18 print("Detected 'q' - stopping the pipeline...")
19 self.stopPipeline()
20
21# with dai.Pipeline() as p:
22p = dai.Pipeline()
23with p:
24 camera = p.create(dai.node.Camera).build()
25 hostDisplay = p.create(HostDisplay).build(camera.requestOutput((300, 300)))
26
27 p.run() # Will block until the pipeline is stopped by someone else (in this case it's the display node)需要帮助?
请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。