Host Display
This example demonstrates how to use aHostDisplay
node within a DepthAI pipeline to display frames obtained from the device using OpenCV. The HostDisplay
node is a custom host node that receives image frames from the DepthAI pipeline and displays them on the host machine using OpenCV's imshow
function.The examples serves as an alternative to manually calling .get()
on pipeline queues to retrieve frames and display them using OpenCV. Instead, the HostDisplay
node handles the frame retrieval and display process, making it easier to visualize the output of the pipeline. It is the most basic example of a custom host node.This example requires the DepthAI v3 API, see installation instructions.Pipeline
Source Code
Python
C++
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)
Need assistance?
Head over to Discussion Forum for technical support or any other questions you might have.