@rosepetal/node-red-contrib-image-tools 1.7.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/.github/workflows/build-prebuild.yml +1 -1
  2. package/README.md +39 -21
  3. package/docs/index.md +156 -0
  4. package/docs/nodes/blend/add-bbs.md +116 -0
  5. package/docs/nodes/blend/add-mask.md +67 -224
  6. package/docs/nodes/blend/add-masks.md +74 -196
  7. package/docs/nodes/blend/blend.md +84 -200
  8. package/docs/nodes/io/folder-in.md +92 -0
  9. package/docs/nodes/io/image-in.md +61 -52
  10. package/docs/nodes/io/image-out.md +114 -93
  11. package/docs/nodes/mix/advanced-mosaic.md +124 -78
  12. package/docs/nodes/mix/concat.md +71 -56
  13. package/docs/nodes/mix/mosaic.md +81 -91
  14. package/docs/nodes/specialized/cropBB.md +76 -214
  15. package/docs/nodes/specialized/heat-diff.md +111 -0
  16. package/docs/nodes/specialized/image-align.md +125 -387
  17. package/docs/nodes/transform/color-convert.md +101 -0
  18. package/docs/nodes/transform/crop.md +56 -58
  19. package/docs/nodes/transform/draw.md +46 -26
  20. package/docs/nodes/transform/filter.md +110 -46
  21. package/docs/nodes/transform/padding.md +55 -55
  22. package/docs/nodes/transform/resize.md +81 -56
  23. package/docs/nodes/transform/rotate.md +67 -50
  24. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +11 -4
  25. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +2 -1
  26. package/npm/darwin-arm64/package.json +1 -1
  27. package/npm/darwin-x64/package.json +1 -1
  28. package/npm/linux-arm64/package.json +1 -1
  29. package/npm/linux-x64/package.json +1 -1
  30. package/npm/linuxmusl-x64/package.json +1 -1
  31. package/npm/win32-x64/package.json +1 -1
  32. package/package.json +6 -6
  33. package/rosepetal-image-engine/src/heat-diff.cpp +4 -0
  34. package/rosepetal-image-engine/src/image-align.cpp +71 -3
  35. package/scripts/build-opencv-static.sh +6 -0
@@ -206,7 +206,7 @@ jobs:
206
206
  # macOS ARM64 (Apple Silicon)
207
207
  # =============================================================================
208
208
  darwin-arm64:
209
- runs-on: macos-14
209
+ runs-on: macos-15
210
210
  steps:
211
211
  - uses: actions/checkout@v4
212
212
 
package/README.md CHANGED
@@ -1,9 +1,22 @@
1
1
  # Node-RED Image Processing Toolkit
2
2
 
3
- A comprehensive Node-RED package providing 18 specialized nodes for high-performance image processing using C++ OpenCV backend. Perfect for computer vision workflows, batch processing, and automated image manipulation.
3
+ A comprehensive Node-RED package providing 20 specialized nodes for high-performance image processing using C++ OpenCV backend. Perfect for computer vision workflows, batch processing, and automated image manipulation.
4
4
 
5
5
  ![Demo](assets/flow_time_example.gif)
6
6
 
7
+ ## Documentation
8
+
9
+ | Section | Pages |
10
+ |---------|-------|
11
+ | Overview | [Installation, requirements, nodes, image format and common settings](docs/index.md) |
12
+ | I/O nodes | [image-in](docs/nodes/io/image-in.md) · [folder-in](docs/nodes/io/folder-in.md) · [image-out](docs/nodes/io/image-out.md) |
13
+ | Transform nodes | [resize](docs/nodes/transform/resize.md) · [rotate](docs/nodes/transform/rotate.md) · [crop](docs/nodes/transform/crop.md) · [padding](docs/nodes/transform/padding.md) · [filter](docs/nodes/transform/filter.md) · [draw](docs/nodes/transform/draw.md) · [color-convert](docs/nodes/transform/color-convert.md) |
14
+ | Mix nodes | [concat](docs/nodes/mix/concat.md) · [mosaic](docs/nodes/mix/mosaic.md) · [advanced-mosaic](docs/nodes/mix/advanced-mosaic.md) |
15
+ | Blend nodes | [blend](docs/nodes/blend/blend.md) · [add-mask](docs/nodes/blend/add-mask.md) · [add-masks](docs/nodes/blend/add-masks.md) · [add-bbs](docs/nodes/blend/add-bbs.md) |
16
+ | Specialized nodes | [cropBB](docs/nodes/specialized/cropBB.md) · [image-align](docs/nodes/specialized/image-align.md) · [heat-diff](docs/nodes/specialized/heat-diff.md) |
17
+
18
+ The same pages are published at <https://docs.rosepetal.ai/flows/node-red-contrib-image-tools>.
19
+
7
20
  ## 🚀 Quick Start
8
21
 
9
22
  ### Installation (users)
@@ -22,15 +35,14 @@ For contributors or platforms without a prebuilt binary:
22
35
  ./install.sh
23
36
  # or manual steps:
24
37
  cd rosepetal-image-engine && npm install && npm run build
25
- cd ../node-red-contrib-image-tools && npm install
38
+ cd .. && npm install
26
39
  cd ~/.node-red && npm install /path/to/node-red-contrib-image-tools
27
40
  ```
28
41
  > npm installs fetch prebuilt binaries for common platforms; build from source only if you are developing or a prebuilt is unavailable.
29
42
 
30
43
  ### Requirements
31
- - Node.js 16+ with node-gyp support
32
- - OpenCV 4.x (auto-detected via pkg-config)
33
- - C++ compiler with C++17 support
44
+ - Node.js 18.17+ (required by the `sharp` dependency) and Node-RED 1.0.0+
45
+ - Only to build from source: node-gyp build tools, OpenCV 4.x (auto-detected via pkg-config) and a C++ compiler with C++17 support
34
46
 
35
47
  ## 📋 Node Categories
36
48
 
@@ -38,6 +50,7 @@ cd ~/.node-red && npm install /path/to/node-red-contrib-image-tools
38
50
  | Node | Purpose | Key Features |
39
51
  |------|---------|-------------|
40
52
  | **[image-in](docs/nodes/io/image-in.md)** | Load images from filesystem | JPEG/PNG/WebP/etc. support, Sharp backend |
53
+ | **[folder-in](docs/nodes/io/folder-in.md)** | Emit the images of a folder one by one | Configurable interval, loop or one-shot mode, start/stop button |
41
54
  | **[image-out](docs/nodes/io/image-out.md)** | Save images with timestamp naming | Auto-naming, overwrite protection, format conversion |
42
55
 
43
56
  ### Transform Nodes - Image Processing
@@ -49,6 +62,7 @@ cd ~/.node-red && npm install /path/to/node-red-contrib-image-tools
49
62
  | **[padding](docs/nodes/transform/padding.md)** | Add configurable margins | Color customization, flexible sizing |
50
63
  | **[filter](docs/nodes/transform/filter.md)** | Apply enhancement filters | Blur, sharpen, edge, emboss, Gaussian |
51
64
  | **[draw](docs/nodes/transform/draw.md)** | Overlay points and lines on images | Normalized coordinates, typed inputs, C++ compositing |
65
+ | **[color-convert](docs/nodes/transform/color-convert.md)** | Convert images between color spaces | GRAY, RGB, RGBA, BGR and BGRA |
52
66
 
53
67
  ### Mix Nodes - Image Composition
54
68
  | Node | Purpose | Key Features |
@@ -62,12 +76,15 @@ cd ~/.node-red && npm install /path/to/node-red-contrib-image-tools
62
76
  |------|---------|-------------|
63
77
  | **[blend](docs/nodes/blend/blend.md)** | Alpha blend two images with opacity | Background removal, color tolerance |
64
78
  | **[add-mask](docs/nodes/blend/add-mask.md)** | Apply polygon-based masks to regions | Coordinate arrays, mask strength control |
79
+ | **[add-masks](docs/nodes/blend/add-masks.md)** | Apply multiple polygon masks colored by class | Class color mappings, global mask strength |
80
+ | **[add-bbs](docs/nodes/blend/add-bbs.md)** | Draw bounding boxes with labels on images | Tag and confidence labels, color per tag |
65
81
 
66
82
  ### Specialized Nodes - AI/ML Integration
67
83
  | Node | Purpose | Key Features |
68
84
  |------|---------|-------------|
69
85
  | **[cropBB](docs/nodes/specialized/cropBB.md)** | Extract crops from AI bounding boxes | Object detection integration, confidence filtering |
70
- | **[image-align](docs/nodes/specialized/image-align.md)** | Ultra-fast image alignment using ECC algorithm | Translation correction, speed presets, real-time processing |
86
+ | **[image-align](docs/nodes/specialized/image-align.md)** | Align an image to a reference with ECC, ORB/SIFT features, or both | Translation to homography models, speed presets |
87
+ | **[heat-diff](docs/nodes/specialized/heat-diff.md)** | Heat map of the difference between two images | Colormaps, blur and threshold, difference statistics |
71
88
 
72
89
  ## Architecture & Performance
73
90
 
@@ -98,20 +115,21 @@ cd ~/.node-red && npm install /path/to/node-red-contrib-image-tools
98
115
 
99
116
  ### Project Structure
100
117
  ```
101
- node-red-contrib-image-tools/
102
- ├── docs/nodes/ # Individual node documentation
103
- ├── nodes/ # Node-RED node implementations
104
- │ ├── io/ # I/O nodes
105
- │ ├── transform/ # Transform nodes
106
- │ ├── mix/ # Composition nodes
107
- │ ├── blend/ # Blending nodes
108
- │ └── specialized/ # AI/ML nodes
109
- ├── lib/ # Shared utilities
110
- └── assets/ # Documentation assets
111
-
112
- rosepetal-image-engine/ # C++ processing engine
113
- ├── src/ # OpenCV implementations
114
- ├── binding.gyp # Node.js addon configuration
118
+ docs/nodes/ # Individual node documentation
119
+ assets/ # Documentation assets
120
+
121
+ node-red-contrib-image-tools/ # Node-RED package sources
122
+ ├── nodes/ # Node-RED node implementations
123
+ │ ├── io/ # I/O nodes
124
+ │ ├── transform/ # Transform nodes
125
+ │ ├── mix/ # Composition nodes
126
+ │ ├── blend/ # Blending nodes
127
+ │ └── specialized/ # AI/ML nodes
128
+ └── lib/ # Shared utilities
129
+
130
+ rosepetal-image-engine/ # C++ processing engine
131
+ ├── src/ # OpenCV implementations
132
+ ├── binding.gyp # Node.js addon configuration
115
133
  └── package.json
116
134
  ```
117
135
 
@@ -144,7 +162,7 @@ rosepetal-image-engine/ # C++ processing engine
144
162
 
145
163
  ## 📄 License
146
164
 
147
- This project is part of the Rosepetal development toolkit for Node-RED image processing applications.
165
+ Apache-2.0 (see the `LICENSE` file). This project is part of the Rosepetal development toolkit for Node-RED image processing applications.
148
166
 
149
167
  ---
150
168
 
package/docs/index.md ADDED
@@ -0,0 +1,156 @@
1
+ ---
2
+ title: "Image Processing Toolkit for Node-RED"
3
+ description: "Nodes for Node-RED that load, resize, crop, rotate, filter, compose, blend, align and save images with a native OpenCV addon. Part of @rosepetal/node-red-contrib-image-tools."
4
+ head:
5
+ - - meta
6
+ - name: "keywords"
7
+ content: "node-red, image processing, opencv, resize, crop, rotate, filter, mosaic, blend, mask, bounding box, image alignment, rosepetal"
8
+ - - meta
9
+ - property: "og:title"
10
+ content: "Image Processing Toolkit - @rosepetal/node-red-contrib-image-tools"
11
+ - - meta
12
+ - property: "og:description"
13
+ content: "Nodes for Node-RED that load, resize, crop, rotate, filter, compose, blend, align and save images with a native OpenCV addon."
14
+ ---
15
+
16
+ # Image Processing Toolkit for Node-RED
17
+
18
+ `@rosepetal/node-red-contrib-image-tools` provides 20 nodes for Node-RED that load, transform, compose, annotate, compare and save images. The image operations run in a native C++ addon built on OpenCV; loading and saving also use `sharp`.
19
+
20
+ ![A Node-RED flow of image nodes, each showing its processing time in its status](../assets/flow_time_example.gif)
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ cd ~/.node-red
26
+ npm install @rosepetal/node-red-contrib-image-tools
27
+ ```
28
+
29
+ Or search `@rosepetal/node-red-contrib-image-tools` in the Node-RED Palette Manager.
30
+
31
+ npm fetches a prebuilt native addon, with OpenCV statically linked, for **linux-x64** and **linux-arm64** (glibc), **linuxmusl-x64** (Alpine) and **darwin-arm64**. On any other platform the addon has to be built from source: see [Building from source](#building-from-source).
32
+
33
+ ## Requirements
34
+
35
+ - Node.js 18.17 or later (the `sharp` dependency supports `^18.17.0 || ^20.3.0 || >=21.0.0`)
36
+ - Node-RED >= 1.0.0
37
+ - One of the platforms above, or the tools to build the addon: OpenCV 4.x, a C++17 compiler and node-gyp
38
+
39
+ ## Nodes
40
+
41
+ All node types are prefixed with `rp-` and appear under the **RP Image** category in the editor. Flows saved with the earlier type names, without the prefix (`resize`, `crop` and so on), keep working: the published package also registers those names, hidden from the palette (every node except `rp-heat-diff`, which never had another name).
42
+
43
+ ### I/O
44
+
45
+ | Node | Purpose |
46
+ |------|---------|
47
+ | **[rp-image-in](./nodes/io/image-in.md)** | Load an image file from disk into the raw image object that the other nodes use |
48
+ | **[rp-folder-in](./nodes/io/folder-in.md)** | Emit the image files of a folder one by one at a set interval, in a loop or once, started and stopped with the node's button |
49
+ | **[rp-image-out](./nodes/io/image-out.md)** | Save images to disk as JPEG, PNG, WebP or BMP, one per message or many from an array, with timestamped file names, overwrite protection, a file limit and a disk limit |
50
+
51
+ ### Transform
52
+
53
+ | Node | Purpose |
54
+ |------|---------|
55
+ | **[rp-resize](./nodes/transform/resize.md)** | Scale images to a fixed size or by a factor, keeping the aspect ratio when one dimension is left empty |
56
+ | **[rp-rotate](./nodes/transform/rotate.md)** | Rotate images by an angle in degrees and fill the uncovered area with a pad color |
57
+ | **[rp-crop](./nodes/transform/crop.md)** | Extract a rectangular region, with normalized (0-1) or pixel coordinates |
58
+ | **[rp-padding](./nodes/transform/padding.md)** | Add a margin of a solid color on each side |
59
+ | **[rp-filter](./nodes/transform/filter.md)** | Apply blur, sharpening, edge detection, emboss, Gaussian blur, Otsu threshold, histogram equalization or CLAHE |
60
+ | **[rp-draw](./nodes/transform/draw.md)** | Overlay points and line segments, with normalized coordinates, color and opacity |
61
+ | **[rp-color-convert](./nodes/transform/color-convert.md)** | Convert images between the GRAY, RGB, RGBA, BGR and BGRA color spaces |
62
+
63
+ ### Mix
64
+
65
+ | Node | Purpose |
66
+ |------|---------|
67
+ | **[rp-concat](./nodes/mix/concat.md)** | Join an array of images into one, to the right, left, down or up, padding or resizing the ones that differ in size |
68
+ | **[rp-mosaic](./nodes/mix/mosaic.md)** | Place the images of an array on a canvas at the positions set in the node, in pixels or normalized coordinates |
69
+ | **[rp-advanced-mosaic](./nodes/mix/advanced-mosaic.md)** | Compose the images of an array on a canvas with a position, size, rotation and stacking order per image, set in a visual editor |
70
+
71
+ ### Blend
72
+
73
+ | Node | Purpose |
74
+ |------|---------|
75
+ | **[rp-blend](./nodes/blend/blend.md)** | Blend two images with an adjustable opacity, with optional alpha compositing and background color removal |
76
+ | **[rp-add-mask](./nodes/blend/add-mask.md)** | Blend a polygon mask over an image, from normalized polygon coordinates, with a fill color and a strength |
77
+ | **[rp-add-masks](./nodes/blend/add-masks.md)** | Blend several polygon or bitmap masks over an image, with a color per class |
78
+ | **[rp-add-bbs](./nodes/blend/add-bbs.md)** | Draw bounding boxes on an image, labelled with their tag and confidence, with a color per tag |
79
+
80
+ ### Specialized
81
+
82
+ | Node | Purpose |
83
+ |------|---------|
84
+ | **[rp-cropBB](./nodes/specialized/cropBB.md)** | Extract one crop per bounding box of an inference result, filtered by a minimum confidence |
85
+ | **[rp-image-align](./nodes/specialized/image-align.md)** | Align a target image to a reference image with ECC, with ORB or SIFT features, or with features refined by ECC |
86
+ | **[rp-heat-diff](./nodes/specialized/heat-diff.md)** | Compute the per-pixel absolute difference of two images as a color-mapped heat image, with optional difference statistics |
87
+
88
+ ## Quick start
89
+
90
+ ```
91
+ [inject] → [rp-image-in] → [rp-resize] → [rp-image-out]
92
+ ```
93
+
94
+ 1. In `rp-image-in`, set **File Path** to an image file on the Node-RED host. Any incoming message makes the node load the file into `msg.payload`.
95
+ 2. In `rp-resize`, set **Width** and leave **Height** empty to keep the aspect ratio.
96
+ 3. In `rp-image-out`, set **Folder Path**. With the default settings the image is saved there as `image_<timestamp>.jpg`.
97
+
98
+ ## Image format
99
+
100
+ The nodes pass raw images between them as objects:
101
+
102
+ ```javascript
103
+ {
104
+ data: Buffer, // Raw pixel data
105
+ width: number, // Image width in pixels
106
+ height: number, // Image height in pixels
107
+ channels: number, // Channel count (1, 3, 4)
108
+ colorSpace: string, // "GRAY", "RGB", "RGBA", "BGR", "BGRA"
109
+ dtype: string // "uint8"
110
+ }
111
+ ```
112
+
113
+ `rp-image-in` and `rp-folder-in` produce this object, with `colorSpace` `GRAY`, `RGB` or `RGBA`. A raw image without `colorSpace` is read as GRAY, RGB or RGBA from its channel count; a `colorSpace` that does not match the channel count is rejected. The transform, mix, blend and specialized nodes (except `rp-cropBB`) also accept an encoded JPEG, PNG, WebP or BMP `Buffer` in its place and decode it in the addon (as RGB, RGBA or GRAY); `rp-image-out` accepts JPEG, PNG and WebP buffers.
114
+
115
+ ## Common settings
116
+
117
+ The transform, mix, blend and specialized nodes share these settings:
118
+
119
+ - **Input from / Output to**: where the image is read and where the result is written, as a `msg` property or a `flow` / `global` context key. The result goes to `msg.payload` by default. The nodes that read two inputs or extra data (`rp-blend`, `rp-add-mask`, `rp-add-masks`, `rp-add-bbs`, `rp-cropBB`, `rp-image-align` and `rp-heat-diff`) read and write `msg` properties only (except **Stats to** of `rp-heat-diff`), although their editor also offers `flow` and `global`.
120
+ - **Output Format**: `raw` (the image object, the default) or an encoded `Buffer` in `jpg`, `png` or `webp`. **Quality** (1-100, default 90) applies to JPEG and WebP; **PNG Optimize** sets PNG compression level 6 instead of 0; the WebP options **Lossless**, **Smart Subsample** and **Effort** (0-6) make `sharp` encode the WebP instead of OpenCV. JPEG drops the alpha channel.
121
+ - **Debug**: shows a preview of the result in the editor, with a configurable width (200 pixels by default).
122
+ - **Inference** (`rp-resize`, `rp-rotate`, `rp-crop`, `rp-padding`, `rp-concat`, `rp-mosaic` and `rp-advanced-mosaic`, under **Advanced options**): when checked, the detections and segmentations read from `msg.inference` (by default) get the same geometric change as the image and are written back, so that their coordinates match the output image (for `rp-advanced-mosaic`, not for every rotated or one-side-resized placement: see its page). Detections are objects with `raw_boxes` (four normalized corner points) and segmentations objects with `polygons` (normalized points); other entries pass unchanged. For the nodes that combine several images, `msg.inference` holds one such array per input image and the result is a single array.
123
+
124
+ `rp-resize`, `rp-rotate`, `rp-crop`, `rp-padding`, `rp-filter` and `rp-color-convert` take one image or an array of images, and process the images of an array in parallel. `rp-image-align` and `rp-heat-diff` take two images or two arrays of the same length, paired by index.
125
+
126
+ ## Timing and errors
127
+
128
+ The transform, mix, blend and specialized nodes, and `rp-folder-in`, record their processing time in `msg.performance.rpimage.<key>` as `{ conversion, task, total }`, in milliseconds. `<key>` is the name of the node, or its type when it has no name, in lower case and with every run of other characters replaced by `_` (`rp_resize`).
129
+
130
+ When the processing fails, the transform, mix, blend and specialized nodes do not stop the flow: they set `msg.error` (`message`, `operation`, `hint`, `details`, `timestamp`, `nodeId`, `nodeName`, `nodeType`, and `validationError: true` when the input was rejected), log a warning, show a red `Error: ...` status and still send the message. The I/O nodes behave differently: see their pages.
131
+
132
+ ## Performance
133
+
134
+ - Decoding, processing and encoding run on the libuv thread pool, not on the Node-RED event loop; the JavaScript layer only validates and routes messages.
135
+ - The pool has 4 threads by default and is shared with `sharp` and file I/O. Under heavy concurrency, raise it before starting Node-RED: `UV_THREADPOOL_SIZE=8 node-red`.
136
+ - Keep the `raw` output format between the nodes of a chain and encode only at the end.
137
+
138
+ ## Building from source
139
+
140
+ For contributors, and for platforms without a prebuilt addon:
141
+
142
+ ```bash
143
+ git clone https://github.com/rosepetal-ai/node-red-contrib-image-tools.git
144
+ cd node-red-contrib-image-tools
145
+ ./install.sh
146
+ ```
147
+
148
+ The script installs the build tools and OpenCV with the system's package manager (apt, dnf, yum, pacman or Homebrew) when `pkg-config` does not find OpenCV 4, builds the C++ addon, and offers to install the package into `~/.node-red`.
149
+
150
+ ## Related packages
151
+
152
+ Several examples in these pages collect images into an array with Array-In and Array-Out nodes. They are `rp-array-in` and `rp-array-out`, which moved from this package to [`@rosepetal/node-red-contrib-utils`](https://docs.rosepetal.ai/flows/node-red-contrib-utils).
153
+
154
+ ## License
155
+
156
+ Apache-2.0. The package is published on npm as [`@rosepetal/node-red-contrib-image-tools`](https://www.npmjs.com/package/@rosepetal/node-red-contrib-image-tools).
@@ -0,0 +1,116 @@
1
+ ---
2
+ title: "Add-BBs Node - Draw Bounding Boxes with Labels"
3
+ description: "Draw the bounding boxes of a detection result on an image in Node-RED, labelled with their tag and confidence, with a color per tag. Part of @rosepetal/node-red-contrib-image-tools."
4
+ head:
5
+ - - meta
6
+ - name: "keywords"
7
+ content: "node-red, add-bbs, bounding box, object detection, draw boxes, labels, confidence, opencv, rosepetal"
8
+ - - meta
9
+ - property: "og:title"
10
+ content: "Add-BBs Node - @rosepetal/node-red-contrib-image-tools"
11
+ - - meta
12
+ - property: "og:description"
13
+ content: "Draw the bounding boxes of a detection result on an image in Node-RED, labelled with their tag and confidence, with a color per tag."
14
+ ---
15
+
16
+ # Add-BBs Node
17
+
18
+ > **Type**: `rp-add-bbs` · **Category**: Blend · **Since**: v1.1.3
19
+
20
+ ## Overview
21
+
22
+ Add-BBs draws the boxes of an object detection result on the image: the outline of each box in the colour of its tag, and a label with the tag and the confidence. Boxes may be rotated. For segmentation masks instead of boxes, use [add-masks](./add-masks.md); to cut the boxes out as separate images, use [cropBB](../specialized/cropBB.md).
23
+
24
+ **Use cases**
25
+ - Show what a detection model found, on a dashboard or in saved images
26
+ - Keep an annotated copy of every inspected part
27
+ - Highlight only some classes (for example defects) with **Only Draw Mapped Tags**
28
+
29
+ ## Inputs
30
+
31
+ Only `msg` properties are read: the editor also offers `flow` and `global`, but the node reads the typed text as a `msg` path.
32
+
33
+ - **Image** (`msg.payload.image` by default): a raw image object or an encoded JPEG/PNG/WebP/BMP `Buffer`.
34
+ - **Boxes Array** (`msg.payload` by default): an array of detections. Each one needs:
35
+ - `tag`: a non-empty string, the class of the box
36
+ - a box in normalized coordinates (0-1), in one of these forms: `raw_boxes` (four `[x, y]` corner points), `4points` (`{ x0, y0, x1, y1, x2, y2, x3, y3 }`), `xywhr` (`{ x, y, w, h, r }`, top-left corner and rotation in degrees), `cwh` (`{ x, y, w, h, r }`, centre) or `2points` (`{ xmin, ymin, xmax, ymax }`). When the object has no `raw_boxes`, the node adds them to it, computed from the other form.
37
+ - `confidence` (optional): 0-1; without it the label shows 100.0%.
38
+
39
+ The default paths (`msg.payload.image` and `msg.payload`) cannot both hold data in a normal message, so set at least one of them. For example, with **Image** `msg.image` and **Boxes Array** `msg.boxes`:
40
+
41
+ ```javascript
42
+ msg.image = image; // raw image object or encoded Buffer
43
+ msg.boxes = [
44
+ { tag: "scratch", confidence: 0.91, "2points": { xmin: 0.12, ymin: 0.30, xmax: 0.25, ymax: 0.41 } },
45
+ { tag: "dent", confidence: 0.67, raw_boxes: [[0.6,0.2],[0.8,0.2],[0.8,0.5],[0.6,0.5]] }
46
+ ];
47
+ ```
48
+
49
+ ## Outputs
50
+
51
+ One output.
52
+
53
+ - **Output** (`msg.payload` by default; a `msg` property): the image with the boxes, with the size and color space of the input, as a raw image object or an encoded `Buffer` (JPEG, PNG, WebP).
54
+ - `msg.performance.rpimage.<key>`: `{ conversion, task, total }` in milliseconds.
55
+ - On failure: `msg.error` (`message`, `operation`, `hint`, `details`, `timestamp`, `nodeId`, `nodeName`, `nodeType`, and `validationError: true` for invalid input), with the input image written to **Output**; the message is still sent.
56
+
57
+ ## Configuration
58
+
59
+ | Field | Type | Default | Description |
60
+ |---|---|---|---|
61
+ | Name | string | empty | Label of the node; also the key of its timings in `msg.performance.rpimage` |
62
+ | Image | msg path | `msg.payload.image` | The image to draw on |
63
+ | Boxes Array | msg path | `msg.payload` | The detections |
64
+ | Output | msg path | `msg.payload` | Where the result is written |
65
+ | Output Format | enum | Raw (fastest) | Raw (fastest), JPEG, PNG or WebP |
66
+ | Quality | number | `90` | JPEG and WebP quality, 1-100 |
67
+ | PNG Optimize | boolean | off | PNG compression level 6 instead of 0 |
68
+ | Lossless / Smart Subsample / Effort | boolean / boolean / number | off / off / empty | WebP options; when any is set the WebP is encoded with `sharp` |
69
+ | Debug / Debug Width | boolean / number | off / `200` | **Show processed image** under the node in the editor |
70
+ | Show Tag Name | boolean | on | Put the tag in the label |
71
+ | Show Confidence | boolean | on | Put the confidence in the label, as a percentage with one decimal |
72
+ | Only Draw Mapped Tags | boolean | off | Draw only the boxes whose tag is in Tag Color Mappings |
73
+ | Box Thickness | number | `2` | 1-10, scaled with the image size |
74
+ | Font Size | number | `0.5` | 0.3-2.0, scaled with the image size |
75
+ | Tag Color Mappings | list | empty | Tag names with a colour each, added with **Add Tag Mapping** |
76
+
77
+ ### Drawing
78
+
79
+ - Each box is drawn as a closed outline through its four corners, so rotated boxes are drawn rotated.
80
+ - The label (`scratch (91.0%)`, `scratch` or `91.0%`, depending on the two Show options) is written in black on a filled rectangle of the box colour, above the topmost corner of the box. With both Show options off, no label is drawn.
81
+ - Line thickness and text size grow with the image: the thickness in pixels is about Box Thickness × √(width × height) / 1000, at least 1.
82
+ - Tags without a mapping get an automatic colour, chosen again for every message: pure red for the first one when there are no mappings, otherwise the colour of a fixed palette of 216 that differs most from those already in use. The colour of an unmapped tag therefore depends on the mappings and on the other unmapped tags of the message and their order; map the tags that need a fixed colour.
83
+
84
+ ### Status
85
+
86
+ - Green dot `OK: <n> img in <t> ms (conv <c> ms | task <k> ms)`, where `<n>` is the number of boxes drawn.
87
+ - An empty array writes the image to Output unchanged, with `OK: 0 img ...`.
88
+ - Red ring `Error: <first 30 characters>` on failure.
89
+
90
+ ## Examples
91
+
92
+ ```
93
+ [camera] → [inference] → [Function: msg.image = image; msg.boxes = detections] → [rp-add-bbs: Image msg.image, Boxes Array msg.boxes] → [rp-image-out]
94
+ ```
95
+
96
+ Saves every inspected image with its detections drawn.
97
+
98
+ ```
99
+ [detector] → [rp-add-bbs: Only Draw Mapped Tags, scratch → #ff0000, dent → #ffaa00] → [dashboard image]
100
+ ```
101
+
102
+ Shows only the two defect classes, each in a fixed colour.
103
+
104
+ ## Troubleshooting
105
+
106
+ - **`Boxes input must be an array`** — Cause: **Boxes Array** points at the object that contains the detections, or at nothing. · Solution: point it at the array itself.
107
+ - **`Box coordinates out of range [0,1] at index <i>`** — Cause: the box is in pixels. · Solution: divide by the image width and height first.
108
+ - **`Invalid tag at index <i>: must be a non-empty string`** or **`Empty tag at index <i>: tag cannot be empty`** — Cause: a detection has no `tag`, or it is not a string. · Solution: copy the class name into `tag` (for example from `class_name`).
109
+ - **`Invalid box object at index <i>: 'raw_boxes' property must be an array`** — Cause: the detection has none of the box forms listed above. · Solution: add `raw_boxes` or one of the other forms.
110
+ - **Boxes missing** — Cause: **Only Draw Mapped Tags** is on and the tag is not in the mappings (names must match exactly). · Solution: add the tag or turn the option off.
111
+
112
+ ## See Also
113
+
114
+ - [add-masks](./add-masks.md): draw segmentation masks coloured by class
115
+ - [cropBB](../specialized/cropBB.md): cut each box out as its own image
116
+ - [draw](../transform/draw.md): draw points and lines