Keep an image history on a panel
An operator who looks up from the line has missed the last few products. Rosepetal's image widgets keep them on the panel: the last four images, the last reject and a history of every inspection that the operator can scroll through and open. In this guide you add the three to the panel of a biscuit line.
What you will learn
- How to show the last images and the last reject
- How to keep a history of inspections that survives a restart
- What message each widget reads
Before you start
You need a panel page; here «Biscuit line», with three empty groups: «Last packs», «History» and «Last reject». Pages and groups are explained in Show inspection results on a panel. The flow streams packs of biscuits through a segmentation model; two rp-resize nodes make a JPEG of each pack for the screen and a small one for the thumbnails, and the function node «To the history» puts them, with the outline of each biscuit and the verdict, in the shape the widgets read. Its code is at the end of this page.
1. Add an image log
Type ui-image-log in «filter nodes», drag the «image log» node, in the «Renders» category, onto the workspace and wire it to the first output of «To the history». The image log is the history: a grid of every image it receives, newest first, which the operator can scroll through and open.

2. Choose where it keeps the images
Double-click it and choose the group, here «History». «Images folder» is where it keeps the history on the controller: one small file per image in a metadata folder inside it, so that the history comes back after a restart. Leave the default, /opt/storage/images/log/imageShowDir. «Images per page» is how many images it shows before «Load more». Untick «Show mask checkbox» and «Show bbox checkbox»: these images only have outlines.

3. Name the image type
Further down, set «Image types» to 1 and name the type «Pack»: the widget shows the image the message carries under that name, in imageShow.Pack. With several types, the operator switches between them in the image, for example between the original and one with the defects marked.

4. Save each image in that folder
The log keeps an image while its file is in «Images folder», named <name>_<type>.jpg, and drops it when the file is gone. Add an rp-save-file node on the fourth output, which carries the JPEG and that name. Set «Folder» to /opt/storage/images/log/imageShowDir, «Filename» to msg.filename, and «Max Files» to how many images to keep, here 200: the oldest files are deleted, and the history forgets them.

5. Show the last four packs
Click «Done». Add an «image queue» node (ui-image-queue) on the second output and open it. Choose the group «Last packs» and the same image type, «Pack». It always shows four cards, the newest at the top, and the operator opens one to see it whole.

6. Show the last reject
Click «Done». Add a «last error» node (ui-last-error) on the third output, which only carries the packs that fail, and set it up the same way in the group «Last reject». It shows one image, the last one it received, until the next reject.

7. Deploy and start the line
Click «Deploy» and press the «start» inject node. Each pack goes through the model and «To the history» sends it to the three widgets.
8. Open the panel
Open «Panels». «Last packs» shows the last four packs, «History» every pack inspected, newest first, with its verdict, the number of biscuits and the time, and «Last reject» the last pack that failed. The cards and the bars are green for OK and red for NOK.

9. Open an image of the history
Click a card of the history. The image opens with the outline and the confidence of each biscuit, the result, the date and the name of the image. The arrows at the bottom go to the next and previous images, «POLYGONS» hides the outlines, and the buttons on the image zoom, adjust the brightness and show it full screen.

10. Look at the last reject
Click «Close». «Last reject» keeps the last pack that failed in view, so the operator sees what went wrong even when the line has moved on; click it to open it the same way.

The messages for the widgets
The three widgets read the same image object: the image and its thumbnail under the name of the image type, the outlines with positions from 0 to 1, the result and the verdict. Each one takes it in a message of its own, which «To the history» sends on its four outputs:
// Each pack gets a name that starts with the time: the log sorts by it
const name = Date.now() + "_pack";
const biscuits = msg.inference.filter((b) => b.confidence >= 0.5);
const result = biscuits.length === 4 ? "OK" : "NOK";
const color = result === "OK" ? "rgb(46,160,67)" : "rgb(229,57,53)";
const light = (points) => points.filter((p, i) => i % 6 === 0);
const image = {
name,
date: new Date().toISOString(),
result,
isAnomalous: result === "NOK",
tag: biscuits.length + " biscuits",
imageShow: { Pack: {
imageData: "data:image/jpeg;base64," + msg.jpg.toString("base64"),
imageDataThumbnail: "data:image/jpeg;base64," + msg.thumb.toString("base64"),
} },
polygons: biscuits.flatMap((b) => b.polygons.map((points) => ({ points: light(points), color, tag: b.tag, confidence: b.confidence }))),
};
return [
{ payload: { action: "imageInput", image } }, // 1: the image log
{ payload: { action: "push", image } }, // 2: the last four
result === "NOK" ? { payload: image } : null, // 3: the last reject
{ payload: msg.jpg, filename: name + "_Pack.jpg" }, // 4: the file the log keeps
];imageShow.Pack.imageDataandimageDataThumbnailare the image and its thumbnail, as data URLs or addresses.imageShow.Pack.bboxtakes boxes instead, for a detection model:{ x_rel, y_rel, w_rel, h_rel, tag, color }.isAnomalouscolours the card red (true) or green (false);resultandtagare the texts on it.- The image log adds an image with
{ action: "imageInput", image }, and the image queue with{ action: "push", image }; the last error takes the image itself. Sending"clear"empties the queue and the last error.
Good to know
- After a restart. The image log reads its folder again when the flow starts, so the history is still there. The queue and the last error only keep what they received since then.
- Upload and download. Select cards of the history (click with Shift held, or drag over them) to download the images, or to send them to the flow with «Upload»: the image log sends
{ name }of each one on its output, for a flow that uploads them to a dataset and answers with{ action: "uploadStatus", name, done: true }. See Collect images from a flow into a dataset. - Thumbnails. «Annotations on thumbnails» draws the outlines on the cards too; the operator can turn them off with «Show annotations».
Next steps
Recorded on Rosepetal release 1.8.15, Node-RED 5.0.10.