Messages
Messages are sent between linked Nodes. The only way nodes communicate with each other is by sending messages from one to another. On the table of contents (left side of the page) all DepthAI message types are listed under theMessages
entry. You can click on them to find out more.Creating a message in Script node
A DepthAI message can be created either on the device, by a node automatically or manually inside the Script node. In below example, the code is taken from the Script Camera Control example, where the Camera Control message is created inside the Script node every second and sent to the Camera's input (cam.inputControl
).Python
1script = pipeline.create(dai.node.Script)
2script.setScript("""
3 # Create a message
4 ctrl = CameraControl(1)
5 # Configure the message
6 ctrl.setCaptureStill(True)
7 # Send the message from the Script node
8 node.io['out'].send(ctrl)
9""")
Creating a message on the Host
It can also be created on a host computer and sent to the device via input queue. In the example below, we have removed all the code that isn't relevant to showcase how a message can be created on the host and sent to the device.Python
1imgFrame = dai.ImgFrame()
2frame = np.ones((300, 300, 3), np.uint8) * 255
3imgFrame.setData(frame)
4imgFrame.setWidth(frame.shape[1])
5imgFrame.setHeight(frame.shape[0])
6imgFrame.setType(dai.ImgFrame.Type.BGR888i)
7
8with dai.Pipeline() as pipeline:
9 # Define source and output
10 script = pipeline.create(dai.node.Script)
11 cam_input_q = script.inputs["frame"].createInputQueue()
12 script.setScript("""
13 import time
14 while True:
15 frame = node.io["frame"].get()
16 if frame:
17 node.warn("Received frame")
18 time.sleep(0.1)
19 """)
20
21 pipeline.start()
22 while pipeline.isRunning():
23
24 cam_input_q.send(imgFrame)
25 time.sleep(1)