MQTT Image Sampling : Historize as TimeSeries in Docker

🖼️ Storing Images from your Machine Vision system in 10 minutes.

Machine vision use case

How to store images for a machine vision application ? MQtt Protocol can be very useful for that and that's what we're going to see in this article. Usually, the industrial use case for quality control is to detect some defects using a camera. But we can also use those machine vision camera to run more advanced analytics so either some machine learning algorithms that you will run over an entire sample of images. So in order to get that sample you need to store let's say once every second the image is coming from the camera so we can use MQTT to do that there are multiple ways but uh that's what we are going to see today.

Explore the architecture of our system here

👉 Visualize | 📽️ Vidéo (00 min : 42 s)

Our architecture

As a first step you need an MQTT Broker. So the first step is to familiarize with the MQTT Protocol but the broker is really the central piece. Then, you need to have a publisher so your machine visual camera publish the images via MQTT. So in that case once 1000 images/s so 1000 frames per second. What we want to do is to take a saple of that and store it once every second in an historian. So we encode those images just to make the storage simpler and we store those images into NoSQL database which is MongoDB because it's pretty useful for large document storage.

We can usually add an IoT platform in the middle just to orchestrate the whole thing or to monitor and make some little ajustements. In that case, I'm using Ignition as a suscriber to that same broker.

Complete part for this section here:

👉 Visualize | 📽️ Vidéo (02 min : 32 s)

Broker EMQX

Let's start with the Broker and then see the publish sidem the subscribe side and the historian.

Complete part for this section here:

👉 Visualize | 📽️ Vidéo (01 min : 3 s)

Publisher mqtt images on python

Once the broker is set up, then you go and configure your publisher. The publisher is our script.

Complete part for this section here:

👉 Visualize | 📽️ Vidéo (00 min : 26 s)

Subscriber ignition

Once we are published those images, they arrived to the broker into a topic, for our demo, the defect topic. And we want to subscribe to that topic by using Ignition as the IoT platform.

Complete part for this section here:

👉 Visualize | 📽️ Vidéo (03 min : 08 s)

Historian mongoDB

After that, the most critical part is to historize those images that we get every second. We use a Tag Change Script to do that so every time this tag (the MQTT topic which we subscribed) changes, we run that script which is basically taking MongoDB Connector Ignition and inserting these images into our collection.

Complete part for this section here:

👉 Visualize | 📽️ Vidéo (01 min : 14 s)

Github repo

The complete Github Repo here:

Complete part for this section here:

👉 Visualize | 📽️ Vidéo (00 min : 53 s)

Marc Akoto – Intégrateur SCADA