# Messages

Messages are sent between linked [Nodes](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes.md). 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 the `Messages` 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](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/script.md) node. In below example, the code is
taken from the [Script Camera Control](https://docs.luxonis.com/software-v3/depthai/examples/script_camera_control.md) example,
where the [Camera Control](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/camera_control.md) message is
created inside the Script node every second and sent to the
[Camera's](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/camera.md) input (`cam.inputControl`).

```python

script = pipeline.create(dai.node.Script)
script.setScript("""
  # Create a message
  ctrl = CameraControl(1)
  # Configure the message
  ctrl.setCaptureStill(True)
  # Send the message from the Script node
  node.io['out'].send(ctrl)
""")
```

## 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
imgFrame = dai.ImgFrame()
frame = np.ones((300, 300, 3), np.uint8) * 255
imgFrame.setData(frame)
imgFrame.setWidth(frame.shape[1])
imgFrame.setHeight(frame.shape[0])
imgFrame.setType(dai.ImgFrame.Type.BGR888i)

with dai.Pipeline() as pipeline:
    # Define source and output
    script = pipeline.create(dai.node.Script)
    cam_input_q = script.inputs["frame"].createInputQueue()
    script.setScript("""
    import time
    while True:
        frame = node.io["frame"].get()
        if frame:
          node.warn("Received frame")
        time.sleep(0.1)
    """)

    pipeline.start()
    while pipeline.isRunning():

        cam_input_q.send(imgFrame)
        time.sleep(1)
```

## Remapping transformable messages

Image-derived messages can carry an `ImgTransformation` that records how a stream was resized, cropped, rotated, aligned, or
otherwise remapped in the pipeline. Messages that implement the
[`Transformable`](https://docs.luxonis.com/software-v3/depthai/api/cpp.md) interface can use that data to return a copy in another
frame's coordinate system:

```python
remappedMessage = message.transformTo(targetTransformation)
```

In practice, `targetTransformation` usually comes from the destination
[ImgFrame](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/img_frame.md) that you want to draw on or
compare against.

DepthAI 3.7.1 exposes this flow on:

 * [ImgDetections](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/img_detections.md)
 * [SpatialImgDetections](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/spatial_img_detections.md)
 * [AprilTags](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/april_tags.md)
 * [Tracklets](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/tracklets.md)
 * [SegmentationMask](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/segmentation_mask.md)

For segmentation outputs, note that `SegmentationMask.transformTo(...)` currently returns a copy without remapping mask pixels.
When you need a mask in another coordinate system, align the source frames before generating the mask.
