Skip to content

Save images and results to disk ​

An inspection is easier to trust, and to improve, when its images and results are kept. Two nodes save them on the controller's disk: rp-image-out saves images, rp-save-file saves any data, such as the predictions of a model. Both name each file for you and can keep only the latest ones, so the disk never fills up. In this guide you keep every pack of biscuits that goes through a flow, named after its verdict, with the predictions next to it.

What you will learn

  • How to save images with a name that says what they are
  • How to save the predictions of a model as a JSON file
  • How to keep only the latest files

Before you start

Here the flow streams the packs of a dataset through a segmentation model, and a function node gives each one its verdict, OK or NOK, in msg.payload; see Decide pass or fail from the predictions. The image travels in msg.image and the predictions in msg.inference.

1. Add a node that saves images ​

Type rp-image-out in «filter nodes», drag the node after the function node and wire them. Open it. Set «Input from» to msg.image, where the image travels, and «Folder Path» to the folder on the controller, here /tmp/line-check/images. The folder is created if it is not there.

Add a node that saves images

2. Name each image after its verdict ​

Each image is named with a prefix and the date and time it was saved, in UTC down to the millisecond: [prefix]_YYYYMMDD_HHMMSS-mmmZ.jpg. Set the type of «Filename Prefix» to msg. and write payload: the verdict becomes the start of the name, as in NOK_20261123_122120-068Z.jpg, so the rejected packs are easy to find. «Full Filename» names the file entirely, when you need another pattern.

Name each image after its verdict

3. Keep only the latest images ​

Leave «Output Format» on JPEG, which keeps files small. Write 5 in «Max Images»: once the folder holds 5 images, each new one deletes the oldest, so the disk never fills up. On a line, keep as many as the disk allows, for example a few days of production. «Disk Limit» stops saving when the disk is that full.

Keep only the latest images

4. Save the predictions too ​

Click «Done». Add an rp-save-file node after the function node and open it. It saves whatever it is given: an image, text, or data as JSON. Set «Input» to msg.inference, the predictions, «Folder» to /tmp/line-check/results and «File Type» to «JSON». With «Filename» empty, each file is named data_ and the date and time. Write 5 in «Max Files» here too.

Save the predictions too

5. See where each file went ​

«Result to» is where the node leaves a note of what it saved: msg.savedFile, with the path, the name and the size of the file. Click «Done», add a debug node after it and set it to show msg.savedFile.

6. Run the line ​

Click «Deploy» and press the «start» inject node. Under rp-image-out you see the name of each image it saves, OK or NOK and the time, and the debug panel lists each JSON file with its path and size. The first time, while the folder does not exist yet, rp-save-file warns that it could not check the disk; it creates the folder and saves the file all the same.

Run the line

7. Stop it ​

Press the «stop» inject node. However many packs went through, each folder holds only the latest 5.

Stop it

Good to know ​

  • Where to save. The controller keeps its images under /opt/storage/images. A guide like this one writes to a temporary folder instead, /tmp/line-check, and deletes it at the end.
  • A switch on the button. The button on the side of rp-image-out turns saving off and on without deploying, for example while the line runs a test batch.
  • Many files at once. In «Multiple images» mode (or «Multiple files» in rp-save-file), the node saves a list of objects, each with its own image, name and folder: the crops of every object a model found, for example.
  • Other formats. «Output Format» also saves PNG, WebP and BMP. PNG keeps every pixel, at several times the size of a JPEG.

Next steps ​

Recorded on Rosepetal release 1.8.15, Node-RED 5.0.10.