Forwarding camera images from Carla simulator with MQTT
In the public sponsored research project MANNHEIM-FlexKI we are using the Carla simulator as a data generation / simulation system for the optimization of vulnerable road user detection (as a use case for general AI optimization for various systems).
In our setup, we are using Carla on a PC with a decent GPU to simulate the traffic and then send it to a Jetson (Nano/Orin/Xavier) or other systems to do the AI processing.
Some of our Carla systems run on Windows and we would like to share a few findings:
Carla Installation
Forwarding images - Gstreamer
Recommended by LinkedIn
Forwarding images - MQTT
image = image_queue.get()
img = np.reshape(np.copy(image.raw_data), (image.height, image.width, 4))
paho_client.publish("carla-image", img.tobytes())
And on the receiver side:
def on_message(client, userdata, msg):
image = np.frombuffer(msg.payload, dtype=np.uint8).reshape(args.width, args.height, 4)
cv2.imwrite('received_image.png', image)
# Create an MQTT client and attach the on_message callback
client = mqtt.Client(client_id="carla-img", callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
client.on_message = on_message
Let us know if this article was useful for your work with the great Carla simulator.