@rosepetal/node-red-contrib-image-tools 1.1.3 → 1.2.0
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.
- package/README.md +1 -13
- package/node-red-contrib-image-tools/lib/node-utils.js +218 -17
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +64 -9
- package/node-red-contrib-image-tools/nodes/blend/add-mask.js +81 -9
- package/node-red-contrib-image-tools/nodes/blend/add-masks.js +64 -8
- package/node-red-contrib-image-tools/nodes/blend/blend.js +64 -10
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +12 -1
- package/node-red-contrib-image-tools/nodes/io/image-in.js +10 -2
- package/node-red-contrib-image-tools/nodes/io/image-out.js +25 -3
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +52 -26
- package/node-red-contrib-image-tools/nodes/mix/concat.js +46 -9
- package/node-red-contrib-image-tools/nodes/mix/mosaic.js +52 -15
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +53 -5
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +54 -7
- package/node-red-contrib-image-tools/nodes/transform/crop.js +38 -17
- package/node-red-contrib-image-tools/nodes/transform/draw.js +28 -7
- package/node-red-contrib-image-tools/nodes/transform/filter.js +34 -15
- package/node-red-contrib-image-tools/nodes/transform/padding.js +30 -9
- package/node-red-contrib-image-tools/nodes/transform/resize.js +58 -33
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +40 -20
- package/node-red-contrib-image-tools/package.json +1 -8
- package/package.json +1 -1
- package/rosepetal-image-engine/binding.gyp +5 -23
- package/rosepetal-image-engine/src/add-mask.cpp +2 -2
- package/rosepetal-image-engine/src/add-masks.cpp +2 -2
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +3 -4
- package/rosepetal-image-engine/src/blend.cpp +2 -2
- package/rosepetal-image-engine/src/concat.cpp +2 -2
- package/rosepetal-image-engine/src/crop.cpp +3 -3
- package/rosepetal-image-engine/src/draw.cpp +1 -1
- package/rosepetal-image-engine/src/filter.cpp +3 -3
- package/rosepetal-image-engine/src/mosaic.cpp +4 -5
- package/rosepetal-image-engine/src/padding.cpp +4 -3
- package/rosepetal-image-engine/src/resize.cpp +101 -23
- package/rosepetal-image-engine/src/rotate.cpp +3 -6
- package/rosepetal-image-engine/src/utils.h +46 -8
- package/docs/nodes/io/array-in.md +0 -119
- package/docs/nodes/io/array-out.md +0 -150
- package/docs/nodes/io/array-select.md +0 -157
- package/docs/nodes/io/queue.md +0 -57
- package/docs/nodes/io/save-file.md +0 -30
- package/docs/nodes/util/block-detect.md +0 -46
- package/node-red-contrib-image-tools/nodes/io/array-in.html +0 -110
- package/node-red-contrib-image-tools/nodes/io/array-in.js +0 -113
- package/node-red-contrib-image-tools/nodes/io/array-out.html +0 -125
- package/node-red-contrib-image-tools/nodes/io/array-out.js +0 -213
- package/node-red-contrib-image-tools/nodes/io/array-select.html +0 -156
- package/node-red-contrib-image-tools/nodes/io/array-select.js +0 -187
- package/node-red-contrib-image-tools/nodes/io/queue.html +0 -119
- package/node-red-contrib-image-tools/nodes/io/queue.js +0 -191
- package/node-red-contrib-image-tools/nodes/io/save-file.html +0 -243
- package/node-red-contrib-image-tools/nodes/io/save-file.js +0 -440
- package/node-red-contrib-image-tools/nodes/util/block-detect.html +0 -85
- package/node-red-contrib-image-tools/nodes/util/block-detect.js +0 -136
- package/node-red-contrib-image-tools/nodes/util/clean-debug.html +0 -201
- package/node-red-contrib-image-tools/nodes/util/clean-debug.js +0 -393
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Node-RED Image Processing Toolkit
|
|
2
2
|
|
|
3
|
-
A comprehensive Node-RED package providing
|
|
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.
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
@@ -39,11 +39,6 @@ cd ~/.node-red && npm install /path/to/node-red-contrib-image-tools
|
|
|
39
39
|
|------|---------|-------------|
|
|
40
40
|
| **[image-in](docs/nodes/io/image-in.md)** | Load images from filesystem | JPEG/PNG/WebP/etc. support, Sharp backend |
|
|
41
41
|
| **[image-out](docs/nodes/io/image-out.md)** | Save images with timestamp naming | Auto-naming, overwrite protection, format conversion |
|
|
42
|
-
| **[save-file](docs/nodes/io/save-file.md)** | Write any payload to disk | Auto-detect images/JSON/text, overwrite guard, format control |
|
|
43
|
-
| **[array-in](docs/nodes/io/array-in.md)** | Collect data into positioned arrays | Dynamic positioning, batch collection |
|
|
44
|
-
| **[array-out](docs/nodes/io/array-out.md)** | Assemble arrays from multiple sources | Timeout protection, ordered assembly |
|
|
45
|
-
| **[array-select](docs/nodes/io/array-select.md)** | Extract elements with flexible selection | Python-like slicing, range selection |
|
|
46
|
-
| **[queue](docs/nodes/io/queue.md)** | Buffer and pace message delivery | FIFO gating, rate control, timed expiry |
|
|
47
42
|
|
|
48
43
|
### Transform Nodes - Image Processing
|
|
49
44
|
| Node | Purpose | Key Features |
|
|
@@ -74,13 +69,6 @@ cd ~/.node-red && npm install /path/to/node-red-contrib-image-tools
|
|
|
74
69
|
| **[cropBB](docs/nodes/specialized/cropBB.md)** | Extract crops from AI bounding boxes | Object detection integration, confidence filtering |
|
|
75
70
|
| **[image-align](docs/nodes/specialized/image-align.md)** | Ultra-fast image alignment using ECC algorithm | Translation correction, speed presets, real-time processing |
|
|
76
71
|
|
|
77
|
-
### Utility Nodes - Diagnostics
|
|
78
|
-
| Node | Purpose | Key Features |
|
|
79
|
-
|------|---------|-------------|
|
|
80
|
-
| **clean-debug** | Safe debug output for large payloads | Buffer cleaning, sidebar/console toggles, enable/disable button |
|
|
81
|
-
| **[block-detect](docs/nodes/util/block-detect.md)** | Background watchdog for event-loop blocking | No wires, configurable thresholds, live status metrics |
|
|
82
|
-
|
|
83
|
-
|
|
84
72
|
## Architecture & Performance
|
|
85
73
|
|
|
86
74
|
### Two-Tier Design
|
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
* @author Rosepetal
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
let sharp;
|
|
8
|
+
try {
|
|
9
|
+
sharp = require('sharp');
|
|
10
|
+
} catch (err) {
|
|
11
|
+
sharp = null;
|
|
12
|
+
}
|
|
8
13
|
|
|
9
14
|
|
|
10
15
|
module.exports = function(RED) {
|
|
@@ -35,6 +40,55 @@ module.exports = function(RED) {
|
|
|
35
40
|
image.hasOwnProperty('height') &&
|
|
36
41
|
image.hasOwnProperty('data')):
|
|
37
42
|
|
|
43
|
+
const normalizeNumber = (value) => {
|
|
44
|
+
if (typeof value === 'number') return value;
|
|
45
|
+
if (typeof value === 'string') {
|
|
46
|
+
const trimmed = value.trim();
|
|
47
|
+
if (trimmed === '') return value;
|
|
48
|
+
const parsed = Number(trimmed);
|
|
49
|
+
return Number.isFinite(parsed) ? parsed : value;
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const normalizeData = (data) => {
|
|
55
|
+
if (!data) return data;
|
|
56
|
+
if (Buffer.isBuffer(data)) return data;
|
|
57
|
+
if (ArrayBuffer.isView(data)) {
|
|
58
|
+
return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
59
|
+
}
|
|
60
|
+
if (data instanceof ArrayBuffer) {
|
|
61
|
+
return Buffer.from(data);
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(data)) {
|
|
64
|
+
return Buffer.from(data);
|
|
65
|
+
}
|
|
66
|
+
if (typeof data === 'object') {
|
|
67
|
+
if (data.type === 'Buffer' && Array.isArray(data.data)) {
|
|
68
|
+
return Buffer.from(data.data);
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(data.data)) {
|
|
71
|
+
return Buffer.from(data.data);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return data;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Normalize width/height to numbers when possible
|
|
78
|
+
const width = normalizeNumber(image.width);
|
|
79
|
+
const height = normalizeNumber(image.height);
|
|
80
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) {
|
|
81
|
+
node.warn(`Invalid image dimensions: width=${image.width}, height=${image.height}`);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Normalize data for serialized Buffer/typed arrays
|
|
86
|
+
const normalizedData = normalizeData(image.data);
|
|
87
|
+
if (!normalizedData || typeof normalizedData.length !== 'number') {
|
|
88
|
+
node.warn('Image data is missing or not a valid buffer/array');
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
38
92
|
// Validate dtype (only uint8 supported for now)
|
|
39
93
|
if (image.dtype && !CONSTANTS.SUPPORTED_DTYPES.includes(image.dtype)) {
|
|
40
94
|
node.warn(`Unsupported dtype: ${image.dtype}. Supported values: ${CONSTANTS.SUPPORTED_DTYPES.join(', ')}`);
|
|
@@ -44,23 +98,28 @@ module.exports = function(RED) {
|
|
|
44
98
|
// Infer channels if not provided
|
|
45
99
|
let channels = image.channels;
|
|
46
100
|
if (!channels) {
|
|
47
|
-
const calculatedChannels =
|
|
101
|
+
const calculatedChannels = normalizedData.length / (width * height);
|
|
48
102
|
if (!Number.isInteger(calculatedChannels)) {
|
|
49
|
-
node.warn(`Cannot infer channels: data.length (${
|
|
103
|
+
node.warn(`Cannot infer channels: data.length (${normalizedData.length}) is not divisible by width*height (${width * height})`);
|
|
50
104
|
return null;
|
|
51
105
|
}
|
|
52
106
|
channels = calculatedChannels;
|
|
53
107
|
}
|
|
54
108
|
|
|
109
|
+
if (typeof channels === 'string' && channels.trim() !== '') {
|
|
110
|
+
const parsedChannels = Number(channels);
|
|
111
|
+
channels = Number.isFinite(parsedChannels) ? parsedChannels : channels;
|
|
112
|
+
}
|
|
113
|
+
|
|
55
114
|
// Validate channels is a number
|
|
56
|
-
if (typeof channels !== 'number') {
|
|
115
|
+
if (typeof channels !== 'number' || !Number.isFinite(channels) || !Number.isInteger(channels)) {
|
|
57
116
|
node.warn(`Channels must be a number, got: ${typeof channels}`);
|
|
58
117
|
return null;
|
|
59
118
|
}
|
|
60
119
|
|
|
61
120
|
// Validate data length matches dimensions
|
|
62
|
-
if (
|
|
63
|
-
node.warn(`Data length mismatch: expected ${
|
|
121
|
+
if (width * height * channels !== normalizedData.length) {
|
|
122
|
+
node.warn(`Data length mismatch: expected ${width * height * channels} bytes (${width}x${height}x${channels}), got ${normalizedData.length} bytes`);
|
|
64
123
|
return null;
|
|
65
124
|
}
|
|
66
125
|
|
|
@@ -78,6 +137,10 @@ module.exports = function(RED) {
|
|
|
78
137
|
}
|
|
79
138
|
}
|
|
80
139
|
|
|
140
|
+
if (typeof colorSpace === 'string') {
|
|
141
|
+
colorSpace = colorSpace.trim().toUpperCase();
|
|
142
|
+
}
|
|
143
|
+
|
|
81
144
|
// Validate colorSpace matches channel count
|
|
82
145
|
if (!CONSTANTS.CHANNEL_MAP.hasOwnProperty(colorSpace)) {
|
|
83
146
|
node.warn(`Unsupported colorSpace: ${colorSpace}. Supported values: ${CONSTANTS.SUPPORTED_COLOR_SPACES.join(', ')}`);
|
|
@@ -91,9 +154,9 @@ module.exports = function(RED) {
|
|
|
91
154
|
|
|
92
155
|
// Return normalized structure
|
|
93
156
|
return {
|
|
94
|
-
data:
|
|
95
|
-
width:
|
|
96
|
-
height:
|
|
157
|
+
data: normalizedData,
|
|
158
|
+
width: width,
|
|
159
|
+
height: height,
|
|
97
160
|
channels: channels,
|
|
98
161
|
colorSpace: colorSpace,
|
|
99
162
|
dtype: image.dtype || 'uint8'
|
|
@@ -125,6 +188,118 @@ module.exports = function(RED) {
|
|
|
125
188
|
return true;
|
|
126
189
|
}
|
|
127
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Safe wrapper around RED.util.getMessageProperty.
|
|
193
|
+
* Node-RED can throw on paths like "images[0]" when the intermediate object is undefined.
|
|
194
|
+
*/
|
|
195
|
+
utils.safeGetMessageProperty = function(msg, path) {
|
|
196
|
+
try {
|
|
197
|
+
return { value: RED.util.getMessageProperty(msg, path), error: null };
|
|
198
|
+
} catch (error) {
|
|
199
|
+
return { value: undefined, error };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
utils.getInputValue = function(node, msg, path, pathType = 'msg') {
|
|
204
|
+
const type = pathType || 'msg';
|
|
205
|
+
if (type === 'msg') {
|
|
206
|
+
return utils.safeGetMessageProperty(msg, path);
|
|
207
|
+
}
|
|
208
|
+
if (type === 'flow') {
|
|
209
|
+
return { value: node.context().flow.get(path), error: null };
|
|
210
|
+
}
|
|
211
|
+
if (type === 'global') {
|
|
212
|
+
return { value: node.context().global.get(path), error: null };
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
return { value: RED.util.evaluateNodeProperty(path, type, node, msg), error: null };
|
|
216
|
+
} catch (error) {
|
|
217
|
+
return { value: undefined, error };
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
utils.setOutputValue = function(node, msg, path, pathType = 'msg', value) {
|
|
222
|
+
const type = pathType || 'msg';
|
|
223
|
+
if (type === 'msg') {
|
|
224
|
+
RED.util.setMessageProperty(msg, path, value);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (type === 'flow') {
|
|
228
|
+
node.context().flow.set(path, value);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (type === 'global') {
|
|
232
|
+
node.context().global.set(path, value);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
RED.util.setMessageProperty(msg, path, value);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
utils._inferErrorHint = function(errorMessage, operation, context = {}) {
|
|
239
|
+
const inputPath = context.inputPath || context.inPath || context.imagePath || context.masksPath;
|
|
240
|
+
|
|
241
|
+
if (/Invalid inputPath\b/.test(errorMessage) || /Invalid .*Path\b/.test(errorMessage) ||
|
|
242
|
+
/Cannot read properties of undefined \(reading '0'\)/.test(errorMessage)) {
|
|
243
|
+
if (inputPath) {
|
|
244
|
+
return `Check that msg has "${inputPath}" before this node. If you use "[0]" indexing, ensure the array exists and is not empty.`;
|
|
245
|
+
}
|
|
246
|
+
return 'Check your input path(s): an intermediate object is undefined (common with "foo[0]" when foo is missing).';
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (errorMessage.includes('not a valid number')) {
|
|
250
|
+
return 'Check the TypedInput type (num/msg/flow/global) and ensure the resolved value exists and is numeric.';
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (/Invalid image/.test(errorMessage) || /image structure/.test(errorMessage) || /image list/.test(errorMessage)) {
|
|
254
|
+
return 'Provide a valid image (Buffer, or {data,width,height,channels,colorSpace,dtype}). Using the "image-in" node output is the easiest way.';
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (/Failed to decode image buffer/.test(errorMessage)) {
|
|
258
|
+
return 'The input Buffer is not a valid encoded image (jpg/png/webp). Ensure upstream provides a real image buffer.';
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (/Could not load the rosepetal-image-engine native addon/.test(errorMessage)) {
|
|
262
|
+
return 'Install the correct prebuilt package for your platform, or build from source (OpenCV 4.x + build tools) and restart Node-RED.';
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (/OpenCV\(/.test(errorMessage) || /cv::/.test(errorMessage)) {
|
|
266
|
+
return 'Native OpenCV error: check your parameters (sizes > 0, multiply factors > 0). If it tries to allocate huge memory, your computed dimensions are wrong.';
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (operation === 'validation') {
|
|
270
|
+
return 'Fix the node configuration or the incoming msg fields based on the validation error details.';
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
utils._safeTopLevelKeys = function(msg) {
|
|
277
|
+
try {
|
|
278
|
+
const keys = Object.keys(msg || {});
|
|
279
|
+
return keys.slice(0, 30);
|
|
280
|
+
} catch {
|
|
281
|
+
return [];
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
utils.explainError = function(error, operation, context = {}) {
|
|
286
|
+
const message = error instanceof Error ? (error.message || String(error)) : String(error);
|
|
287
|
+
const hint = context.hint || utils._inferErrorHint(message, operation, context) || undefined;
|
|
288
|
+
|
|
289
|
+
const details = {
|
|
290
|
+
operation,
|
|
291
|
+
...context
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
if (details.msg && typeof details.msg === 'object') {
|
|
295
|
+
// Avoid putting the whole msg on msg.error; keep only lightweight info.
|
|
296
|
+
details.msgKeys = utils._safeTopLevelKeys(details.msg);
|
|
297
|
+
delete details.msg;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return { message, hint, details };
|
|
301
|
+
}
|
|
302
|
+
|
|
128
303
|
utils.resolveDimension = function(node, type, value, msg) {
|
|
129
304
|
if (!value || String(value).trim() === '') return null;
|
|
130
305
|
let resolvedValue;
|
|
@@ -170,6 +345,9 @@ module.exports = function(RED) {
|
|
|
170
345
|
}
|
|
171
346
|
|
|
172
347
|
utils.rawToJpeg = async function (image, quality = CONSTANTS.DEFAULT_JPEG_QUALITY) {
|
|
348
|
+
if (!sharp) {
|
|
349
|
+
throw new Error('Sharp is not available. Install "sharp" in your Node-RED userDir and restart Node-RED.');
|
|
350
|
+
}
|
|
173
351
|
const normalized = utils.validateImageStructure(image, { warn: () => {} });
|
|
174
352
|
if (!normalized)
|
|
175
353
|
throw new Error('Invalid raw image object supplied to rawToJpeg');
|
|
@@ -232,19 +410,28 @@ module.exports = function(RED) {
|
|
|
232
410
|
const {
|
|
233
411
|
originalPayload,
|
|
234
412
|
outputPath = 'payload',
|
|
235
|
-
|
|
413
|
+
outputPathType = 'msg',
|
|
414
|
+
outputType = 'preserve',
|
|
415
|
+
context = {}
|
|
236
416
|
} = passthroughOptions;
|
|
237
417
|
|
|
238
|
-
const errorMessage
|
|
418
|
+
const { message: errorMessage, hint, details } = utils.explainError(
|
|
419
|
+
error,
|
|
420
|
+
operation,
|
|
421
|
+
{ ...context, msg }
|
|
422
|
+
);
|
|
239
423
|
const errorStack = error instanceof Error ? error.stack : undefined;
|
|
240
424
|
|
|
241
425
|
// Build error object
|
|
242
426
|
msg.error = {
|
|
243
427
|
message: errorMessage,
|
|
244
428
|
operation: operation,
|
|
429
|
+
hint: hint,
|
|
430
|
+
details: details,
|
|
245
431
|
timestamp: new Date().toISOString(),
|
|
246
432
|
nodeId: node.id,
|
|
247
|
-
nodeName: node.name || node.type
|
|
433
|
+
nodeName: node.name || node.type,
|
|
434
|
+
nodeType: node.type
|
|
248
435
|
};
|
|
249
436
|
|
|
250
437
|
if (errorStack) {
|
|
@@ -270,11 +457,14 @@ module.exports = function(RED) {
|
|
|
270
457
|
output = originalPayload;
|
|
271
458
|
}
|
|
272
459
|
|
|
273
|
-
// Set output
|
|
274
|
-
|
|
460
|
+
// Set output (optional)
|
|
461
|
+
if (outputPath) {
|
|
462
|
+
utils.setOutputValue(node, msg, outputPath, outputPathType, output);
|
|
463
|
+
}
|
|
275
464
|
|
|
276
465
|
// Log error and set status
|
|
277
|
-
|
|
466
|
+
const logLine = hint ? `${errorMessage} | Hint: ${hint}` : errorMessage;
|
|
467
|
+
node.warn(logLine);
|
|
278
468
|
node.status({ fill: "red", shape: "ring", text: `Error: ${errorMessage.substring(0, 30)}` });
|
|
279
469
|
|
|
280
470
|
// Send message with error info
|
|
@@ -296,11 +486,18 @@ module.exports = function(RED) {
|
|
|
296
486
|
* @param {object} passthroughOptions - Same options as handleNodeErrorWithPassthrough
|
|
297
487
|
*/
|
|
298
488
|
utils.handleValidationErrorWithPassthrough = function(node, errorMessage, msg, send, done, passthroughOptions = {}) {
|
|
299
|
-
const
|
|
489
|
+
const validation = (typeof errorMessage === 'string')
|
|
490
|
+
? { message: errorMessage }
|
|
491
|
+
: (errorMessage || {});
|
|
492
|
+
|
|
493
|
+
const error = new Error(validation.message || 'Validation error');
|
|
300
494
|
error.validationError = true;
|
|
301
495
|
|
|
302
496
|
// Add validationError flag to the options
|
|
303
|
-
const options = {
|
|
497
|
+
const options = {
|
|
498
|
+
...passthroughOptions,
|
|
499
|
+
context: { ...(passthroughOptions.context || {}), ...(validation.details || {}), hint: validation.hint }
|
|
500
|
+
};
|
|
304
501
|
|
|
305
502
|
utils.handleNodeErrorWithPassthrough(
|
|
306
503
|
node, error, msg, send, done,
|
|
@@ -345,6 +542,10 @@ module.exports = function(RED) {
|
|
|
345
542
|
*/
|
|
346
543
|
utils.debugImageDisplay = async function(image, outputFormat, quality, node, debugEnabled, debugWidth) {
|
|
347
544
|
if (!debugEnabled) return null;
|
|
545
|
+
if (!sharp) {
|
|
546
|
+
node.warn('Debug display requires "sharp" but it is not available.');
|
|
547
|
+
return null;
|
|
548
|
+
}
|
|
348
549
|
|
|
349
550
|
// Validate and set default debug width
|
|
350
551
|
debugWidth = Math.max(1, parseInt(debugWidth) || 200);
|
|
@@ -20,7 +20,25 @@ module.exports = function (RED) {
|
|
|
20
20
|
node.on('input', async (msg, send, done) => {
|
|
21
21
|
// Capture original payload for error passthrough
|
|
22
22
|
const outputPath = config.outputPath || 'payload';
|
|
23
|
-
const
|
|
23
|
+
const imagePath = config.imagePath || 'payload.image';
|
|
24
|
+
const boxesPath = config.boxesPath || 'payload';
|
|
25
|
+
|
|
26
|
+
const { value: originalPayload, error: imagePathErr } =
|
|
27
|
+
NodeUtils.safeGetMessageProperty(msg, imagePath);
|
|
28
|
+
if (imagePathErr) {
|
|
29
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
30
|
+
node,
|
|
31
|
+
{
|
|
32
|
+
message: `Invalid imagePath "${imagePath}": ${imagePathErr.message}`,
|
|
33
|
+
hint: `Ensure "${imagePath}" exists on msg and contains an image.`,
|
|
34
|
+
details: { imagePath, boxesPath, outputPath }
|
|
35
|
+
},
|
|
36
|
+
msg,
|
|
37
|
+
send,
|
|
38
|
+
done,
|
|
39
|
+
{ originalPayload: undefined, outputPath: null, outputType: 'preserve' }
|
|
40
|
+
);
|
|
41
|
+
}
|
|
24
42
|
|
|
25
43
|
try {
|
|
26
44
|
const t0 = performance.now();
|
|
@@ -28,14 +46,37 @@ module.exports = function (RED) {
|
|
|
28
46
|
|
|
29
47
|
/* ▸ Read image and boxes from message -------------------------- */
|
|
30
48
|
// Get base image and boxes array from specified paths
|
|
31
|
-
const image =
|
|
32
|
-
const
|
|
49
|
+
const image = originalPayload;
|
|
50
|
+
const { value: boxesArray, error: boxesErr } =
|
|
51
|
+
NodeUtils.safeGetMessageProperty(msg, boxesPath);
|
|
52
|
+
if (boxesErr) {
|
|
53
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
54
|
+
node,
|
|
55
|
+
{
|
|
56
|
+
message: `Invalid boxesPath "${boxesPath}": ${boxesErr.message}`,
|
|
57
|
+
hint: `Ensure "${boxesPath}" exists on msg and contains an array of boxes.`,
|
|
58
|
+
details: { imagePath, boxesPath, outputPath }
|
|
59
|
+
},
|
|
60
|
+
msg,
|
|
61
|
+
send,
|
|
62
|
+
done,
|
|
63
|
+
{ originalPayload, outputPath, outputType: 'single' }
|
|
64
|
+
);
|
|
65
|
+
}
|
|
33
66
|
|
|
34
67
|
// Validate base image
|
|
35
68
|
const baseImg = NodeUtils.validateImageStructure(image, node);
|
|
36
69
|
if (!baseImg) {
|
|
37
70
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
38
|
-
node,
|
|
71
|
+
node,
|
|
72
|
+
{
|
|
73
|
+
message: 'Base image is invalid or missing',
|
|
74
|
+
hint: `Check that "${imagePath}" contains a valid image (Buffer or raw image object).`,
|
|
75
|
+
details: { imagePath, boxesPath, outputPath }
|
|
76
|
+
},
|
|
77
|
+
msg,
|
|
78
|
+
send,
|
|
79
|
+
done,
|
|
39
80
|
{ originalPayload, outputPath, outputType: 'single' }
|
|
40
81
|
);
|
|
41
82
|
}
|
|
@@ -43,7 +84,15 @@ module.exports = function (RED) {
|
|
|
43
84
|
// Validate boxes input - expect direct array format
|
|
44
85
|
if (!Array.isArray(boxesArray)) {
|
|
45
86
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
46
|
-
node,
|
|
87
|
+
node,
|
|
88
|
+
{
|
|
89
|
+
message: 'Boxes input must be an array',
|
|
90
|
+
hint: `Set "${boxesPath}" to an array of box objects (expected objects with "raw_boxes" and "tag").`,
|
|
91
|
+
details: { boxesPath, outputPath }
|
|
92
|
+
},
|
|
93
|
+
msg,
|
|
94
|
+
send,
|
|
95
|
+
done,
|
|
47
96
|
{ originalPayload, outputPath, outputType: 'single' }
|
|
48
97
|
);
|
|
49
98
|
}
|
|
@@ -189,12 +238,13 @@ module.exports = function (RED) {
|
|
|
189
238
|
|
|
190
239
|
// Debug image display
|
|
191
240
|
let debugFormat = null;
|
|
192
|
-
|
|
241
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
242
|
+
if (debugEnabled) {
|
|
193
243
|
try {
|
|
194
244
|
// Resolve and validate debug width
|
|
195
245
|
let debugWidth = NodeUtils.resolveDimension(
|
|
196
246
|
node,
|
|
197
|
-
config.debugWidthType,
|
|
247
|
+
config.debugWidthType || 'num',
|
|
198
248
|
config.debugWidth,
|
|
199
249
|
msg
|
|
200
250
|
);
|
|
@@ -205,7 +255,7 @@ module.exports = function (RED) {
|
|
|
205
255
|
outputFormat,
|
|
206
256
|
outputQuality,
|
|
207
257
|
node,
|
|
208
|
-
|
|
258
|
+
debugEnabled,
|
|
209
259
|
debugWidth
|
|
210
260
|
);
|
|
211
261
|
|
|
@@ -231,7 +281,12 @@ module.exports = function (RED) {
|
|
|
231
281
|
} catch (err) {
|
|
232
282
|
NodeUtils.handleNodeErrorWithPassthrough(
|
|
233
283
|
node, err, msg, send, done, 'add-bbs processing',
|
|
234
|
-
{
|
|
284
|
+
{
|
|
285
|
+
originalPayload,
|
|
286
|
+
outputPath,
|
|
287
|
+
outputType: 'single',
|
|
288
|
+
context: { imagePath, boxesPath, outputPath }
|
|
289
|
+
}
|
|
235
290
|
);
|
|
236
291
|
}
|
|
237
292
|
});
|
|
@@ -20,7 +20,23 @@ module.exports = function (RED) {
|
|
|
20
20
|
node.on('input', async (msg, send, done) => {
|
|
21
21
|
// Capture original payload for error passthrough
|
|
22
22
|
const outputPath = config.outputPath || 'payload';
|
|
23
|
-
const
|
|
23
|
+
const { value: originalPayload, error: outErr } =
|
|
24
|
+
NodeUtils.safeGetMessageProperty(msg, outputPath);
|
|
25
|
+
if (outErr) {
|
|
26
|
+
// Don't crash on invalid outputPath; just report it and continue without passthrough output set.
|
|
27
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
28
|
+
node,
|
|
29
|
+
{
|
|
30
|
+
message: `Invalid outputPath "${outputPath}": ${outErr.message}`,
|
|
31
|
+
hint: `Set outputPath to a valid msg property path (e.g. "payload").`,
|
|
32
|
+
details: { outputPath }
|
|
33
|
+
},
|
|
34
|
+
msg,
|
|
35
|
+
send,
|
|
36
|
+
done,
|
|
37
|
+
{ originalPayload: undefined, outputPath: null, outputType: 'preserve' }
|
|
38
|
+
);
|
|
39
|
+
}
|
|
24
40
|
|
|
25
41
|
try {
|
|
26
42
|
const t0 = performance.now();
|
|
@@ -28,14 +44,56 @@ module.exports = function (RED) {
|
|
|
28
44
|
|
|
29
45
|
/* ▸ Read image and polygon from message -------------------------- */
|
|
30
46
|
// Get base image and polygon coordinates from specified paths
|
|
31
|
-
const
|
|
32
|
-
const
|
|
47
|
+
const imagePath = config.imagePath || 'payload.image';
|
|
48
|
+
const polygonPath = config.polygonPath || 'payload.default.masks[0].mask[0]';
|
|
49
|
+
|
|
50
|
+
const { value: image, error: imageErr } =
|
|
51
|
+
NodeUtils.safeGetMessageProperty(msg, imagePath);
|
|
52
|
+
if (imageErr) {
|
|
53
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
54
|
+
node,
|
|
55
|
+
{
|
|
56
|
+
message: `Invalid imagePath "${imagePath}": ${imageErr.message}`,
|
|
57
|
+
hint: `Ensure "${imagePath}" exists on msg and contains an image.`,
|
|
58
|
+
details: { imagePath, polygonPath, outputPath }
|
|
59
|
+
},
|
|
60
|
+
msg,
|
|
61
|
+
send,
|
|
62
|
+
done,
|
|
63
|
+
{ originalPayload, outputPath, outputType: 'single' }
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const { value: polygon, error: polygonErr } =
|
|
68
|
+
NodeUtils.safeGetMessageProperty(msg, polygonPath);
|
|
69
|
+
if (polygonErr) {
|
|
70
|
+
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
71
|
+
node,
|
|
72
|
+
{
|
|
73
|
+
message: `Invalid polygonPath "${polygonPath}": ${polygonErr.message}`,
|
|
74
|
+
hint: `Ensure "${polygonPath}" exists on msg and contains polygon coordinates like [[x,y], ...] with values 0..1.`,
|
|
75
|
+
details: { imagePath, polygonPath, outputPath }
|
|
76
|
+
},
|
|
77
|
+
msg,
|
|
78
|
+
send,
|
|
79
|
+
done,
|
|
80
|
+
{ originalPayload, outputPath, outputType: 'single' }
|
|
81
|
+
);
|
|
82
|
+
}
|
|
33
83
|
|
|
34
84
|
// Validate base image
|
|
35
85
|
const baseImg = NodeUtils.validateImageStructure(image, node);
|
|
36
86
|
if (!baseImg) {
|
|
37
87
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
38
|
-
node,
|
|
88
|
+
node,
|
|
89
|
+
{
|
|
90
|
+
message: 'Base image is invalid or missing',
|
|
91
|
+
hint: `Check that "${imagePath}" contains a valid image (Buffer or raw image object).`,
|
|
92
|
+
details: { imagePath, polygonPath, outputPath }
|
|
93
|
+
},
|
|
94
|
+
msg,
|
|
95
|
+
send,
|
|
96
|
+
done,
|
|
39
97
|
{ originalPayload, outputPath, outputType: 'single' }
|
|
40
98
|
);
|
|
41
99
|
}
|
|
@@ -43,7 +101,15 @@ module.exports = function (RED) {
|
|
|
43
101
|
// Validate polygon coordinates
|
|
44
102
|
if (!Array.isArray(polygon)) {
|
|
45
103
|
return NodeUtils.handleValidationErrorWithPassthrough(
|
|
46
|
-
node,
|
|
104
|
+
node,
|
|
105
|
+
{
|
|
106
|
+
message: 'Polygon coordinates must be an array',
|
|
107
|
+
hint: `Set "${polygonPath}" to an array like [[x,y], ...] where x/y are numbers in range 0..1.`,
|
|
108
|
+
details: { polygonPath, outputPath }
|
|
109
|
+
},
|
|
110
|
+
msg,
|
|
111
|
+
send,
|
|
112
|
+
done,
|
|
47
113
|
{ originalPayload, outputPath, outputType: 'single' }
|
|
48
114
|
);
|
|
49
115
|
}
|
|
@@ -118,12 +184,13 @@ module.exports = function (RED) {
|
|
|
118
184
|
|
|
119
185
|
// Debug image display
|
|
120
186
|
let debugFormat = null;
|
|
121
|
-
|
|
187
|
+
const debugEnabled = config.debugEnabled === true || config.debugEnabled === 'true';
|
|
188
|
+
if (debugEnabled) {
|
|
122
189
|
try {
|
|
123
190
|
// Resolve and validate debug width
|
|
124
191
|
let debugWidth = NodeUtils.resolveDimension(
|
|
125
192
|
node,
|
|
126
|
-
config.debugWidthType,
|
|
193
|
+
config.debugWidthType || 'num',
|
|
127
194
|
config.debugWidth,
|
|
128
195
|
msg
|
|
129
196
|
);
|
|
@@ -134,7 +201,7 @@ module.exports = function (RED) {
|
|
|
134
201
|
outputFormat,
|
|
135
202
|
outputQuality,
|
|
136
203
|
node,
|
|
137
|
-
|
|
204
|
+
debugEnabled,
|
|
138
205
|
debugWidth
|
|
139
206
|
);
|
|
140
207
|
|
|
@@ -160,7 +227,12 @@ module.exports = function (RED) {
|
|
|
160
227
|
} catch (err) {
|
|
161
228
|
NodeUtils.handleNodeErrorWithPassthrough(
|
|
162
229
|
node, err, msg, send, done, 'add-mask processing',
|
|
163
|
-
{
|
|
230
|
+
{
|
|
231
|
+
originalPayload,
|
|
232
|
+
outputPath,
|
|
233
|
+
outputType: 'single',
|
|
234
|
+
context: { outputPath }
|
|
235
|
+
}
|
|
164
236
|
);
|
|
165
237
|
}
|
|
166
238
|
});
|