Skip to content

Capture ​

The Capture widget is a complete image-capture page. The operator starts a capture session with a name, the flow saves the images of the cameras into that session's folder, and the widget lists the sessions with their latest images. A session can then be uploaded to datasets or deleted.

The widget does not save images itself. It sets a global flag while a capture runs; the flow routes the images to its own save chain (for example rp-save-file of @rosepetal/node-red-contrib-utils) and sends the result back to this node. Uploads and the dataset list go through the dataset-upload and list-dataset nodes of @rosepetal/node-red-contrib-vision-platform, wired to the outputs and back to the input.

Palette: category Renders, label capture. 1 input, 3 outputs.

What the widget shows ​

  • The Title, the START CAPTURE / STOP CAPTURE button and, while capturing, the session name, its number of images and its start time. START CAPTURE asks for a capture name.
  • Storage: free and total space of the file system of /opt/storage, and the size of the captures. A warning appears when less than 10 GiB are free. The figures need Node.js 18.15 or later; otherwise Storage shows Not available.
  • One row per session, newest first, with its date, number of images, the 12 latest images, and Upload (or Stop while uploading, with done / total) and Delete buttons. A session whose images were all uploaded shows All images uploaded and can be dismissed from the list.
  • Upload opens a dialog with a Suffix and a Dataset for each image source; the dataset list is requested from the flow when the dialog opens. The last choice per source is offered again next time.
  • Delete asks for confirmation and removes the session's folders.

Configuration ​

PropertyDescriptionDefault
NameNode name shown in the editor.''
GroupDashboard group where the widget is displayed.— (required)
LocaleLocale Config for the dates. Without one, dates are day/month/year, 24 h, in the browser's time zone; a date format left on Browser default is also shown as day/month/year.none
SizeWidget width and height (0 = fit to the group). The panel is 95vh high on screens 768 px wide or more.0 x 0
TitleHeader of the panel.CAPTURE
Images pathTraining or Log; <path> below is training or log. Sessions live in /opt/storage/images/<path>/imageSaveDir/<session>, with light WebP copies for the thumbnails in /opt/storage/images/<path>/imageShowDir/<session>. The save chain of the flow must use the same folders.Training
Capture mode globalGlobal context key set to true when a capture starts and to false when it stops.trainingMode
Capture name (flow context)Flow context key set to the session name when a capture starts and to null when it stops.captureName
Thumbnail URL prefixPrefix of the image URLs the widget shows: <prefix>/<path>/imageShowDir/<session>/<file>.webp when the WebP copy exists, else <prefix>/<path>/imageSaveDir/<session>/<file>./nodered/local/fit/400/images
Image sourcesSource names offered in the upload dialog, one field each (Source name 1, Source name 2, ...). Saved in lower case and trimmed; with more than one, empty names are dropped.1 (one empty name)

The capture name is trimmed. It may not be empty, be longer than 120 characters, or contain /, \, .. or control characters, and must not match an existing session.

Input ​

MessageEffect
msg.path (string) and msg.payload.imageSave (array of { filename } or file names)Images saved by the flow, as rp-save-file returns them. msg.path must be a session folder inside imageSaveDir; the session is its last segment. Only image files count (.png, .jpg, .jpeg, .bmp, .webp, .tiff, .tif, .gif, .avif), and not those whose name starts with thumbnails.
msg.done (boolean), msg.imagesLeft, msg.payload (file name)Progress of an upload, one message per image, as dataset-upload sends it. imagesLeft: 0 ends the upload.
msg.datasetsCount (number) and msg.payload (array of { id, name })Dataset list, as list-dataset sends it.
msg.payload = { action: "stopCapture" }Stops the running capture from the flow (it also sends the capture_stop audit message).
msg.payload = "clean"Empties the list of sessions and images shown. Files are not touched: the sessions on disk come back at the next deploy or restart, and a session comes back when an image is saved in it.

Image files are expected to be named <timestamp>_<source> or <timestamp>_<source>_<suffix>, with the timestamp in milliseconds: the widget sorts by it, and the upload counts a file for a source from its name.

Output ​

OutputMessageWhen
1 (dataset-upload){ payload: true, configTraining: [{ sourceName, dataset, suffix, folder }] }UPLOAD confirmed. Only sources with a dataset are included; folder is the session folder. Set the config source of dataset-upload to msg.configTraining.
1{ payload: false }Stop pressed during an upload.
2 (audit){ action, payload, _client }Start, stop, upload start and stop, and delete, with the dashboard connection and user in _client (see below).
3 (list-dataset){ payload: "refresh" }The upload dialog opens.

Audit messages, ready to be routed with a switch on msg.action to ui-audit-manager nodes:

msg.actionmsg.payload
capture_start{ captureName }
capture_stop{ captureName }
capture_start_upload{ groupName, datasets, total }
capture_stop_upload{ groupName }
capture_remove_images{ groupName } (deleting the running session also sends capture_stop)

Flow and global context ​

  • global.<Capture mode global>: true while capturing. The main flow checks it to send the images to the save chain.
  • flow.<Capture name>: the running session name, used by the save chain to build the folder imageSaveDir/<session>.
  • flow.diskLow: true while less than 10 GiB are free on the file system of /opt/storage; the save chain should not save then. The disk is checked every 30 seconds and on every change of the widget.

These are the flow context of the tab that holds the Capture node: the function nodes that read them must be on the same tab.

State and persistence ​

The sessions, the latest images, the datasets and the last upload choice are kept in the dashboard and in <userDir>/capture-store/<node id>.json, and merged at start-up with the session folders found on disk. A redeploy keeps a running capture. After a Node-RED restart the capture goes on only if the global Capture mode global flag is still true (a persistent context store); otherwise it is stopped, without an audit message. An upload never survives a redeploy or a restart. A session that ends without any saved image is removed, with its folders, 5 seconds after the stop; the same clean-up runs at start-up for every session without images that was not uploaded. When an upload finishes with no image left in the session, and the session is not being captured, its folders are removed. Each uploaded image's WebP copy is deleted as soon as the upload confirms it.

Status and errors ​

StatusMeaning
grey ring idleNo capture and no upload.
green dot capturing: <session> (<images>)Capture running.
yellow dot low disk space: <session> (<images>)Capture running with less than 10 GB free.
blue dot uploading <session>: <uploaded>/<total>Upload running.

In the start dialog: Invalid capture name (no "/", "\" or "..") and A capture session named "<name>" already exists.

Warnings in the Node-RED log: ui-capture: images saved in <dir>, outside <imageSaveDir> (check "Images path") for each save result outside the capture folder, and, once per deploy, ui-capture: raw images received; this node does not save them, wire the save chain (rp-save-file) before it when a message has payload.imageSave but is not a save result (no msg.path, or imageSave is not a list). Other messages report files that could not be read, written or deleted, and No group configured.

Usage example ​

  1. The main flow lets images through only while capturing and with enough disk:
js
// function node in the camera flow, before the save chain
if (global.get("trainingMode") !== true || flow.get("diskLow")) return null;
return msg;
  1. The save chain writes each image to /opt/storage/images/training/imageSaveDir/ followed by flow.get("captureName"), with its WebP copy under imageShowDir, and sends this node the folder in msg.path and the saved files in msg.payload.imageSave.
  2. Output 1 goes to dataset-upload (config from msg.configTraining), output 3 to list-dataset, and the outputs of both back to this node's input.
  3. Output 2 goes to a switch on msg.action and from there to one ui-audit-manager per event type.