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)需要帮助?
请前往 OAKChina 官网 获取技术支持或解答您的任何疑问。