@rosepetal/node-red-contrib-image-tools 1.3.2 → 1.4.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.
@@ -28,7 +28,11 @@
28
28
  right :{value:"0"}, rightType :{value:"num"},
29
29
 
30
30
  /* colour */
31
- padColor:{value:"#000000"}
31
+ padColor:{value:"#000000"},
32
+ // Inference transform
33
+ inferenceEnabled:{value:false},
34
+ inferencePath:{value:"inference"}, inferencePathType:{value:"msg"},
35
+ inferenceOutputPath:{value:"inference"}, inferenceOutputPathType:{value:"msg"}
32
36
  },
33
37
  inputs:1, outputs:1,
34
38
  label:function(){ return this.name || "rp-padding"; },
@@ -97,6 +101,21 @@
97
101
  // Store debug state for runtime access
98
102
  $('#node-input-debugEnabled').data('debug-enabled', enabled);
99
103
  });
104
+
105
+ // === Inference Transform Logic ===
106
+ $("#node-input-inferencePath").typedInput({
107
+ default:'msg', types:['msg','flow','global'],
108
+ typeField:"#node-input-inferencePathType"
109
+ });
110
+ $("#node-input-inferenceOutputPath").typedInput({
111
+ default:'msg', types:['msg','flow','global'],
112
+ typeField:"#node-input-inferenceOutputPathType"
113
+ });
114
+ const infCb = $('#node-input-inferenceEnabled');
115
+ const infRows = $('#inference-config-rows');
116
+ function updateInfVis(){ infRows.toggle(infCb.is(':checked')); }
117
+ updateInfVis();
118
+ infCb.on('change', updateInfVis);
100
119
  }
101
120
  };
102
121
  RED.nodes.registerType('rp-padding', _rpNodeCfg);
@@ -278,9 +297,9 @@
278
297
  <input type="hidden" id="node-input-debugWidthType">
279
298
  <span style="margin-left: 10px; color: #666;">pixels</span>
280
299
  </div>
281
-
300
+
282
301
  <hr>
283
-
302
+
284
303
  <strong>Margins (pixels)</strong>
285
304
  <div class="form-row">
286
305
  <label>Top</label>
@@ -307,6 +326,32 @@
307
326
  <label for="node-input-padColor"><i class="fa fa-tint"></i> Colour</label>
308
327
  <input type="color" id="node-input-padColor" style="width:80px;">
309
328
  </div>
329
+
330
+ <!-- Advanced Options -->
331
+ <details id="advanced-options" style="margin-top: 12px;">
332
+ <summary style="cursor: pointer; font-weight: bold; padding: 4px 0;">
333
+ <i class="fa fa-cog"></i> Advanced options
334
+ </summary>
335
+ <div style="margin-top: 8px;">
336
+ <div class="form-row">
337
+ <label for="node-input-inferenceEnabled"><i class="fa fa-crosshairs"></i> Inference</label>
338
+ <input type="checkbox" id="node-input-inferenceEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
339
+ <label for="node-input-inferenceEnabled" style="width:auto; margin-left:5px;">Transform inference coordinates</label>
340
+ </div>
341
+ <div id="inference-config-rows" style="display: none;">
342
+ <div class="form-row">
343
+ <label for="node-input-inferencePath"><i class="fa fa-sign-in"></i> Inf. Input</label>
344
+ <input type="text" id="node-input-inferencePath" style="width:70%;">
345
+ <input type="hidden" id="node-input-inferencePathType">
346
+ </div>
347
+ <div class="form-row">
348
+ <label for="node-input-inferenceOutputPath"><i class="fa fa-sign-out"></i> Inf. Output</label>
349
+ <input type="text" id="node-input-inferenceOutputPath" style="width:70%;">
350
+ <input type="hidden" id="node-input-inferenceOutputPathType">
351
+ </div>
352
+ </div>
353
+ </div>
354
+ </details>
310
355
  </script>
311
356
 
312
357
  <script type="text/x-red" data-template-name="padding">
@@ -374,9 +419,9 @@
374
419
  <input type="hidden" id="node-input-debugWidthType">
375
420
  <span style="margin-left: 10px; color: #666;">pixels</span>
376
421
  </div>
377
-
422
+
378
423
  <hr>
379
-
424
+
380
425
  <strong>Margins (pixels)</strong>
381
426
  <div class="form-row">
382
427
  <label>Top</label>
@@ -403,6 +448,32 @@
403
448
  <label for="node-input-padColor"><i class="fa fa-tint"></i> Colour</label>
404
449
  <input type="color" id="node-input-padColor" style="width:80px;">
405
450
  </div>
451
+
452
+ <!-- Advanced Options -->
453
+ <details id="advanced-options" style="margin-top: 12px;">
454
+ <summary style="cursor: pointer; font-weight: bold; padding: 4px 0;">
455
+ <i class="fa fa-cog"></i> Advanced options
456
+ </summary>
457
+ <div style="margin-top: 8px;">
458
+ <div class="form-row">
459
+ <label for="node-input-inferenceEnabled"><i class="fa fa-crosshairs"></i> Inference</label>
460
+ <input type="checkbox" id="node-input-inferenceEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
461
+ <label for="node-input-inferenceEnabled" style="width:auto; margin-left:5px;">Transform inference coordinates</label>
462
+ </div>
463
+ <div id="inference-config-rows" style="display: none;">
464
+ <div class="form-row">
465
+ <label for="node-input-inferencePath"><i class="fa fa-sign-in"></i> Inf. Input</label>
466
+ <input type="text" id="node-input-inferencePath" style="width:70%;">
467
+ <input type="hidden" id="node-input-inferencePathType">
468
+ </div>
469
+ <div class="form-row">
470
+ <label for="node-input-inferenceOutputPath"><i class="fa fa-sign-out"></i> Inf. Output</label>
471
+ <input type="text" id="node-input-inferenceOutputPath" style="width:70%;">
472
+ <input type="hidden" id="node-input-inferenceOutputPathType">
473
+ </div>
474
+ </div>
475
+ </div>
476
+ </details>
406
477
  </script>
407
478
 
408
479
  <!-- 3 ▸ Help panel --------------------------------------------------------->
@@ -157,6 +157,30 @@ module.exports = function (RED) {
157
157
  taskMs: tMs
158
158
  }, elapsedTime);
159
159
 
160
+ // --- Inference Transform ---
161
+ if (cfg.inferenceEnabled === true || cfg.inferenceEnabled === 'true') {
162
+ try {
163
+ const InfTx = require('../../lib/inference-transform.js');
164
+ const infPath = cfg.inferencePath || 'inference';
165
+ const infPathType = cfg.inferencePathType || 'msg';
166
+ const infOutPath = cfg.inferenceOutputPath || 'inference';
167
+ const infOutPathType = cfg.inferenceOutputPathType || 'msg';
168
+ const { value: inferences } = NodeUtils.getInputValue(node, msg, infPath, infPathType);
169
+
170
+ if (inferences && Array.isArray(inferences) && inferences.length > 0) {
171
+ const origImg = imgs[0];
172
+ const txInfo = InfTx.makePaddingTransform({
173
+ top: tVal, bottom: bVal, left: lVal, right: rVal,
174
+ origW: origImg.width, origH: origImg.height
175
+ });
176
+ const transformed = await InfTx.applyTransform(inferences, txInfo, CppProcessor);
177
+ NodeUtils.setOutputValue(node, msg, infOutPath, infOutPathType, transformed);
178
+ }
179
+ } catch (infErr) {
180
+ node.warn(`Inference transform: ${infErr.message}`);
181
+ }
182
+ }
183
+
160
184
  send(msg); done && done();
161
185
  } catch (err) {
162
186
  NodeUtils.handleNodeErrorWithPassthrough(
@@ -26,7 +26,13 @@
26
26
  // Propiedades para la configuración del Alto (Height)
27
27
  heightMode: { value: "set" },
28
28
  heightValue: { value: "" },
29
- heightType: { value: "num" } // Tipo para el TypedInput
29
+ heightType: { value: "num" }, // Tipo para el TypedInput
30
+ // Inference transform
31
+ inferenceEnabled: { value: false },
32
+ inferencePath: { value: "inference" },
33
+ inferencePathType: { value: "msg" },
34
+ inferenceOutputPath: { value: "inference" },
35
+ inferenceOutputPathType: { value: "msg" }
30
36
  },
31
37
  inputs: 1,
32
38
  outputs: 1,
@@ -154,6 +160,21 @@
154
160
  // Store debug state for runtime access
155
161
  $('#node-input-debugEnabled').data('debug-enabled', enabled);
156
162
  });
163
+
164
+ // === Inference Transform Logic ===
165
+ $("#node-input-inferencePath").typedInput({
166
+ default:'msg', types:['msg','flow','global'],
167
+ typeField:"#node-input-inferencePathType"
168
+ });
169
+ $("#node-input-inferenceOutputPath").typedInput({
170
+ default:'msg', types:['msg','flow','global'],
171
+ typeField:"#node-input-inferenceOutputPathType"
172
+ });
173
+ const infCb = $('#node-input-inferenceEnabled');
174
+ const infRows = $('#inference-config-rows');
175
+ function updateInfVis(){ infRows.toggle(infCb.is(':checked')); }
176
+ updateInfVis();
177
+ infCb.on('change', updateInfVis);
157
178
  }
158
179
  };
159
180
  RED.nodes.registerType('rp-resize', _rpNodeCfg);
@@ -348,7 +369,7 @@
348
369
  <input type="hidden" id="node-input-debugWidthType">
349
370
  <span style="margin-left: 10px; color: #666;">pixels</span>
350
371
  </div>
351
-
372
+
352
373
  <hr>
353
374
 
354
375
  <div class="form-row">
@@ -377,6 +398,32 @@
377
398
  <div class="form-tips">
378
399
  <b>Tip:</b> If a dimension value is left empty, it will be set to 'Auto' to maintain the original aspect ratio.
379
400
  </div>
401
+
402
+ <!-- Advanced Options -->
403
+ <details id="advanced-options" style="margin-top: 12px;">
404
+ <summary style="cursor: pointer; font-weight: bold; padding: 4px 0;">
405
+ <i class="fa fa-cog"></i> Advanced options
406
+ </summary>
407
+ <div style="margin-top: 8px;">
408
+ <div class="form-row">
409
+ <label for="node-input-inferenceEnabled"><i class="fa fa-crosshairs"></i> Inference</label>
410
+ <input type="checkbox" id="node-input-inferenceEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
411
+ <label for="node-input-inferenceEnabled" style="width:auto; margin-left:5px;">Transform inference coordinates</label>
412
+ </div>
413
+ <div id="inference-config-rows" style="display: none;">
414
+ <div class="form-row">
415
+ <label for="node-input-inferencePath"><i class="fa fa-sign-in"></i> Inf. Input</label>
416
+ <input type="text" id="node-input-inferencePath" style="width:70%;">
417
+ <input type="hidden" id="node-input-inferencePathType">
418
+ </div>
419
+ <div class="form-row">
420
+ <label for="node-input-inferenceOutputPath"><i class="fa fa-sign-out"></i> Inf. Output</label>
421
+ <input type="text" id="node-input-inferenceOutputPath" style="width:70%;">
422
+ <input type="hidden" id="node-input-inferenceOutputPathType">
423
+ </div>
424
+ </div>
425
+ </div>
426
+ </details>
380
427
  </script>
381
428
 
382
429
  <script type="text/x-red" data-template-name="resize">
@@ -445,7 +492,7 @@
445
492
  <input type="hidden" id="node-input-debugWidthType">
446
493
  <span style="margin-left: 10px; color: #666;">pixels</span>
447
494
  </div>
448
-
495
+
449
496
  <hr>
450
497
 
451
498
  <div class="form-row">
@@ -474,6 +521,32 @@
474
521
  <div class="form-tips">
475
522
  <b>Tip:</b> If a dimension value is left empty, it will be set to 'Auto' to maintain the original aspect ratio.
476
523
  </div>
524
+
525
+ <!-- Advanced Options -->
526
+ <details id="advanced-options" style="margin-top: 12px;">
527
+ <summary style="cursor: pointer; font-weight: bold; padding: 4px 0;">
528
+ <i class="fa fa-cog"></i> Advanced options
529
+ </summary>
530
+ <div style="margin-top: 8px;">
531
+ <div class="form-row">
532
+ <label for="node-input-inferenceEnabled"><i class="fa fa-crosshairs"></i> Inference</label>
533
+ <input type="checkbox" id="node-input-inferenceEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
534
+ <label for="node-input-inferenceEnabled" style="width:auto; margin-left:5px;">Transform inference coordinates</label>
535
+ </div>
536
+ <div id="inference-config-rows" style="display: none;">
537
+ <div class="form-row">
538
+ <label for="node-input-inferencePath"><i class="fa fa-sign-in"></i> Inf. Input</label>
539
+ <input type="text" id="node-input-inferencePath" style="width:70%;">
540
+ <input type="hidden" id="node-input-inferencePathType">
541
+ </div>
542
+ <div class="form-row">
543
+ <label for="node-input-inferenceOutputPath"><i class="fa fa-sign-out"></i> Inf. Output</label>
544
+ <input type="text" id="node-input-inferenceOutputPath" style="width:70%;">
545
+ <input type="hidden" id="node-input-inferenceOutputPathType">
546
+ </div>
547
+ </div>
548
+ </div>
549
+ </details>
477
550
  </script>
478
551
 
479
552
  <script type="text/x-red" data-help-name="rp-resize">
@@ -180,6 +180,36 @@ module.exports = function (RED) {
180
180
 
181
181
  NodeUtils.setOutputValue(node, msg, outputPath, outputPathType, out);
182
182
 
183
+ // --- Inference Transform ---
184
+ // For resize, normalized coords are invariant (identity transform).
185
+ // Only bitmap masks would need resizing, but we pass through coords unchanged.
186
+ if (config.inferenceEnabled === true || config.inferenceEnabled === 'true') {
187
+ try {
188
+ const InfTx = require('../../lib/inference-transform.js');
189
+ const infPath = config.inferencePath || 'inference';
190
+ const infPathType = config.inferencePathType || 'msg';
191
+ const infOutPath = config.inferenceOutputPath || 'inference';
192
+ const infOutPathType = config.inferenceOutputPathType || 'msg';
193
+ const { value: inferences } = NodeUtils.getInputValue(node, msg, infPath, infPathType);
194
+
195
+ if (inferences && Array.isArray(inferences) && inferences.length > 0) {
196
+ const origImg = inputList[0];
197
+ // Try to get output dims from raw result; fall back to input dims
198
+ const rawResult = results[0] && results[0].image;
199
+ const newW = (rawResult && rawResult.width) || origImg.width;
200
+ const newH = (rawResult && rawResult.height) || origImg.height;
201
+ const txInfo = InfTx.makeResizeTransform({
202
+ origW: origImg.width, origH: origImg.height,
203
+ newW, newH
204
+ });
205
+ const transformed = await InfTx.applyTransform(inferences, txInfo, CppProcessor);
206
+ NodeUtils.setOutputValue(node, msg, infOutPath, infOutPathType, transformed);
207
+ }
208
+ } catch (infErr) {
209
+ node.warn(`Inference transform: ${infErr.message}`);
210
+ }
211
+ }
212
+
183
213
  send(msg);
184
214
  done && done();
185
215
  } catch (err) {
@@ -20,10 +20,16 @@
20
20
  debugWidthType : { value:"num" },
21
21
  angleValue : { value:"90" },
22
22
  angleType : { value:"num" },
23
- padColor : { value:"#000000" } // siempre visible
23
+ padColor : { value:"#000000" }, // siempre visible
24
+ // Inference transform
25
+ inferenceEnabled : { value:false },
26
+ inferencePath : { value:"inference" },
27
+ inferencePathType : { value:"msg" },
28
+ inferenceOutputPath : { value:"inference" },
29
+ inferenceOutputPathType : { value:"msg" }
24
30
  },
25
31
  inputs :1, outputs:1,
26
- icon:"font-awesome/fa-rotate-right",
32
+ icon:"font-awesome/fa-rotate-left",
27
33
  label:function(){ return this.name || "rp-rotate"; },
28
34
 
29
35
  oneditprepare:function(){
@@ -75,6 +81,21 @@
75
81
  // Store debug state for runtime access
76
82
  $('#node-input-debugEnabled').data('debug-enabled', enabled);
77
83
  });
84
+
85
+ // === Inference Transform Logic ===
86
+ $("#node-input-inferencePath").typedInput({
87
+ default:'msg', types:['msg','flow','global'],
88
+ typeField:"#node-input-inferencePathType"
89
+ });
90
+ $("#node-input-inferenceOutputPath").typedInput({
91
+ default:'msg', types:['msg','flow','global'],
92
+ typeField:"#node-input-inferenceOutputPathType"
93
+ });
94
+ const infCb = $('#node-input-inferenceEnabled');
95
+ const infRows = $('#inference-config-rows');
96
+ function updateInfVis(){ infRows.toggle(infCb.is(':checked')); }
97
+ updateInfVis();
98
+ infCb.on('change', updateInfVis);
78
99
  }
79
100
  };
80
101
  RED.nodes.registerType('rp-rotate', _rpNodeCfg);
@@ -242,10 +263,36 @@
242
263
  <input type="hidden" id="node-input-debugWidthType">
243
264
  <span style="margin-left: 10px; color: #666;">pixels</span>
244
265
  </div>
245
-
266
+
246
267
  <hr>
247
268
  <div class="form-row"><label for="node-input-angleValue"><i class="fa fa-refresh"></i> Angle (°)</label><input type="text" id="node-input-angleValue" style="width:70%;"><input type="hidden" id="node-input-angleType"></div>
248
269
  <div class="form-row"><label for="node-input-padColor"><i class="fa fa-tint"></i> Pad colour</label><input type="color" id="node-input-padColor" style="width:80px;"></div>
270
+
271
+ <!-- Advanced Options -->
272
+ <details id="advanced-options" style="margin-top: 12px;">
273
+ <summary style="cursor: pointer; font-weight: bold; padding: 4px 0;">
274
+ <i class="fa fa-cog"></i> Advanced options
275
+ </summary>
276
+ <div style="margin-top: 8px;">
277
+ <div class="form-row">
278
+ <label for="node-input-inferenceEnabled"><i class="fa fa-crosshairs"></i> Inference</label>
279
+ <input type="checkbox" id="node-input-inferenceEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
280
+ <label for="node-input-inferenceEnabled" style="width:auto; margin-left:5px;">Transform inference coordinates</label>
281
+ </div>
282
+ <div id="inference-config-rows" style="display: none;">
283
+ <div class="form-row">
284
+ <label for="node-input-inferencePath"><i class="fa fa-sign-in"></i> Inf. Input</label>
285
+ <input type="text" id="node-input-inferencePath" style="width:70%;">
286
+ <input type="hidden" id="node-input-inferencePathType">
287
+ </div>
288
+ <div class="form-row">
289
+ <label for="node-input-inferenceOutputPath"><i class="fa fa-sign-out"></i> Inf. Output</label>
290
+ <input type="text" id="node-input-inferenceOutputPath" style="width:70%;">
291
+ <input type="hidden" id="node-input-inferenceOutputPathType">
292
+ </div>
293
+ </div>
294
+ </div>
295
+ </details>
249
296
  </script>
250
297
 
251
298
  <script type="text/x-red" data-template-name="rotate">
@@ -300,10 +347,36 @@
300
347
  <input type="hidden" id="node-input-debugWidthType">
301
348
  <span style="margin-left: 10px; color: #666;">pixels</span>
302
349
  </div>
303
-
350
+
304
351
  <hr>
305
352
  <div class="form-row"><label for="node-input-angleValue"><i class="fa fa-refresh"></i> Angle (°)</label><input type="text" id="node-input-angleValue" style="width:70%;"><input type="hidden" id="node-input-angleType"></div>
306
353
  <div class="form-row"><label for="node-input-padColor"><i class="fa fa-tint"></i> Pad colour</label><input type="color" id="node-input-padColor" style="width:80px;"></div>
354
+
355
+ <!-- Advanced Options -->
356
+ <details id="advanced-options" style="margin-top: 12px;">
357
+ <summary style="cursor: pointer; font-weight: bold; padding: 4px 0;">
358
+ <i class="fa fa-cog"></i> Advanced options
359
+ </summary>
360
+ <div style="margin-top: 8px;">
361
+ <div class="form-row">
362
+ <label for="node-input-inferenceEnabled"><i class="fa fa-crosshairs"></i> Inference</label>
363
+ <input type="checkbox" id="node-input-inferenceEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
364
+ <label for="node-input-inferenceEnabled" style="width:auto; margin-left:5px;">Transform inference coordinates</label>
365
+ </div>
366
+ <div id="inference-config-rows" style="display: none;">
367
+ <div class="form-row">
368
+ <label for="node-input-inferencePath"><i class="fa fa-sign-in"></i> Inf. Input</label>
369
+ <input type="text" id="node-input-inferencePath" style="width:70%;">
370
+ <input type="hidden" id="node-input-inferencePathType">
371
+ </div>
372
+ <div class="form-row">
373
+ <label for="node-input-inferenceOutputPath"><i class="fa fa-sign-out"></i> Inf. Output</label>
374
+ <input type="text" id="node-input-inferenceOutputPath" style="width:70%;">
375
+ <input type="hidden" id="node-input-inferenceOutputPathType">
376
+ </div>
377
+ </div>
378
+ </div>
379
+ </details>
307
380
  </script>
308
381
 
309
382
  <script type="text/x-red" data-help-name="rp-rotate">
@@ -154,6 +154,31 @@ module.exports = function (RED) {
154
154
  taskMs: totalTaskMs
155
155
  }, durMs);
156
156
 
157
+ // --- Inference Transform ---
158
+ if (config.inferenceEnabled === true || config.inferenceEnabled === 'true') {
159
+ try {
160
+ const InfTx = require('../../lib/inference-transform.js');
161
+ const infPath = config.inferencePath || 'inference';
162
+ const infPathType = config.inferencePathType || 'msg';
163
+ const infOutPath = config.inferenceOutputPath || 'inference';
164
+ const infOutPathType = config.inferenceOutputPathType || 'msg';
165
+ const { value: inferences } = NodeUtils.getInputValue(node, msg, infPath, infPathType);
166
+
167
+ if (inferences && Array.isArray(inferences) && inferences.length > 0) {
168
+ const origImg = imgs[0];
169
+ const txInfo = InfTx.makeRotateTransform({
170
+ angleDeg: angle,
171
+ origW: origImg.width,
172
+ origH: origImg.height
173
+ });
174
+ const transformed = await InfTx.applyTransform(inferences, txInfo, CppProcessor);
175
+ NodeUtils.setOutputValue(node, msg, infOutPath, infOutPathType, transformed);
176
+ }
177
+ } catch (infErr) {
178
+ node.warn(`Inference transform: ${infErr.message}`);
179
+ }
180
+ }
181
+
157
182
  send(msg);
158
183
  done && done();
159
184
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rosepetal/node-red-contrib-image-tools",
3
- "version": "1.3.2",
3
+ "version": "1.4.1",
4
4
  "description": "Node-RED Image Processing Toolkit",
5
5
  "main": "install.sh",
6
6
  "directories": {
@@ -47,9 +47,6 @@
47
47
  "rp-image-in": "node-red-contrib-image-tools/nodes/io/image-in.js",
48
48
  "rp-folder-in": "node-red-contrib-image-tools/nodes/io/folder-in.js",
49
49
  "rp-image-out": "node-red-contrib-image-tools/nodes/io/image-out.js",
50
- "rp-array-in": "node-red-contrib-image-tools/nodes/io/array-in.js",
51
- "rp-array-out": "node-red-contrib-image-tools/nodes/io/array-out.js",
52
- "rp-array-select": "node-red-contrib-image-tools/nodes/io/array-select.js",
53
50
  "rp-cropBB": "node-red-contrib-image-tools/nodes/specialized/cropBB.js",
54
51
  "rp-image-align": "node-red-contrib-image-tools/nodes/specialized/image-align.js",
55
52
  "rp-resize": "node-red-contrib-image-tools/nodes/transform/resize.js",
@@ -65,37 +62,7 @@
65
62
  "rp-blend": "node-red-contrib-image-tools/nodes/blend/blend.js",
66
63
  "rp-add-mask": "node-red-contrib-image-tools/nodes/blend/add-mask.js",
67
64
  "rp-add-masks": "node-red-contrib-image-tools/nodes/blend/add-masks.js",
68
- "rp-add-bbs": "node-red-contrib-image-tools/nodes/blend/add-bbs.js",
69
- "rp-queue": "node-red-contrib-image-tools/nodes/io/queue.js",
70
- "rp-save-file": "node-red-contrib-image-tools/nodes/io/save-file.js",
71
- "rp-clean-debug": "node-red-contrib-image-tools/nodes/util/clean-debug.js",
72
- "rp-block-detect": "node-red-contrib-image-tools/nodes/util/block-detect.js",
73
- "image-in": "node-red-contrib-image-tools/nodes/io/image-in.js",
74
- "folder-in": "node-red-contrib-image-tools/nodes/io/folder-in.js",
75
- "image-out": "node-red-contrib-image-tools/nodes/io/image-out.js",
76
- "array-in": "node-red-contrib-image-tools/nodes/io/array-in.js",
77
- "array-out": "node-red-contrib-image-tools/nodes/io/array-out.js",
78
- "array-select": "node-red-contrib-image-tools/nodes/io/array-select.js",
79
- "cropBB": "node-red-contrib-image-tools/nodes/specialized/cropBB.js",
80
- "image-align": "node-red-contrib-image-tools/nodes/specialized/image-align.js",
81
- "resize": "node-red-contrib-image-tools/nodes/transform/resize.js",
82
- "rotate": "node-red-contrib-image-tools/nodes/transform/rotate.js",
83
- "crop": "node-red-contrib-image-tools/nodes/transform/crop.js",
84
- "concat": "node-red-contrib-image-tools/nodes/mix/concat.js",
85
- "padding": "node-red-contrib-image-tools/nodes/transform/padding.js",
86
- "filter": "node-red-contrib-image-tools/nodes/transform/filter.js",
87
- "draw": "node-red-contrib-image-tools/nodes/transform/draw.js",
88
- "color-convert": "node-red-contrib-image-tools/nodes/transform/color-convert.js",
89
- "mosaic": "node-red-contrib-image-tools/nodes/mix/mosaic.js",
90
- "advanced-mosaic": "node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js",
91
- "blend": "node-red-contrib-image-tools/nodes/blend/blend.js",
92
- "add-mask": "node-red-contrib-image-tools/nodes/blend/add-mask.js",
93
- "add-masks": "node-red-contrib-image-tools/nodes/blend/add-masks.js",
94
- "add-bbs": "node-red-contrib-image-tools/nodes/blend/add-bbs.js",
95
- "queue": "node-red-contrib-image-tools/nodes/io/queue.js",
96
- "save-file": "node-red-contrib-image-tools/nodes/io/save-file.js",
97
- "clean-debug": "node-red-contrib-image-tools/nodes/util/clean-debug.js",
98
- "block-detect": "node-red-contrib-image-tools/nodes/util/block-detect.js"
65
+ "rp-add-bbs": "node-red-contrib-image-tools/nodes/blend/add-bbs.js"
99
66
  }
100
67
  }
101
68
  }
@@ -12,7 +12,8 @@
12
12
 
13
13
  // Structure for bounding box information
14
14
  struct BBoxInfo {
15
- cv::Rect boundingRect; // Pixel coordinates
15
+ cv::Rect boundingRect; // Axis-aligned bounding rect (for label positioning)
16
+ std::vector<cv::Point> cornersPx; // 4 oriented corner points in pixels (TL, TR, BR, BL)
16
17
  std::string className;
17
18
  float confidence;
18
19
  cv::Scalar bgrColor; // Pre-computed BGR color (0-255)
@@ -197,14 +198,29 @@ public:
197
198
  color[2] * 255.0f // R
198
199
  );
199
200
 
200
- // Convert normalized coordinates to pixels
201
- cv::Rect bbox;
202
- bbox.x = static_cast<int>(corners[0].x * imageMat.cols);
203
- bbox.y = static_cast<int>(corners[0].y * imageMat.rows);
204
- bbox.width = static_cast<int>((corners[2].x - corners[0].x) * imageMat.cols);
205
- bbox.height = static_cast<int>((corners[2].y - corners[0].y) * imageMat.rows);
201
+ // Convert normalized corners to pixel coordinates
202
+ std::vector<cv::Point> pixelCorners;
203
+ pixelCorners.reserve(4);
204
+ float minX = corners[0].x, maxX = corners[0].x;
205
+ float minY = corners[0].y, maxY = corners[0].y;
206
+ for (int i = 0; i < 4; i++) {
207
+ int px = static_cast<int>(corners[i].x * imageMat.cols);
208
+ int py = static_cast<int>(corners[i].y * imageMat.rows);
209
+ px = std::max(0, std::min(imageMat.cols - 1, px));
210
+ py = std::max(0, std::min(imageMat.rows - 1, py));
211
+ pixelCorners.emplace_back(px, py);
212
+ minX = std::min(minX, corners[i].x);
213
+ maxX = std::max(maxX, corners[i].x);
214
+ minY = std::min(minY, corners[i].y);
215
+ maxY = std::max(maxY, corners[i].y);
216
+ }
206
217
 
207
- // Clamp to image bounds
218
+ // Axis-aligned bounding rect (for label positioning)
219
+ cv::Rect bbox;
220
+ bbox.x = static_cast<int>(minX * imageMat.cols);
221
+ bbox.y = static_cast<int>(minY * imageMat.rows);
222
+ bbox.width = static_cast<int>((maxX - minX) * imageMat.cols);
223
+ bbox.height = static_cast<int>((maxY - minY) * imageMat.rows);
208
224
  bbox.x = std::max(0, std::min(imageMat.cols - 1, bbox.x));
209
225
  bbox.y = std::max(0, std::min(imageMat.rows - 1, bbox.y));
210
226
  bbox.width = std::min(bbox.width, imageMat.cols - bbox.x);
@@ -226,6 +242,7 @@ public:
226
242
  // Store bbox info with pre-computed values
227
243
  BBoxInfo info;
228
244
  info.boundingRect = bbox;
245
+ info.cornersPx = pixelCorners;
229
246
  info.className = className;
230
247
  info.confidence = confidence;
231
248
  info.bgrColor = bgrColor;
@@ -300,29 +317,39 @@ protected:
300
317
 
301
318
  // Process each bounding box
302
319
  for (const auto& bbox : bboxInfos) {
303
- // Draw bounding box rectangle with faster LINE_4
304
- cv::rectangle(result, bbox.boundingRect, bbox.bgrColor, actualBoxThickness, cv::LINE_4);
320
+ // Draw oriented bounding box as a closed polygon
321
+ const cv::Point* pts = bbox.cornersPx.data();
322
+ const int npts = static_cast<int>(bbox.cornersPx.size());
323
+ cv::polylines(result, &pts, &npts, 1, true, bbox.bgrColor, actualBoxThickness, cv::LINE_4);
305
324
 
306
325
  // Draw label if there's text
307
326
  if (!bbox.labelText.empty()) {
308
327
 
309
- // Pre-calculated positions
310
- const int textX = bbox.boundingRect.x + 2;
311
- const int textY = bbox.boundingRect.y - 3;
328
+ // Find the topmost corner (smallest Y) for label anchor
329
+ int topIdx = 0;
330
+ for (int i = 1; i < npts; i++) {
331
+ if (bbox.cornersPx[i].y < bbox.cornersPx[topIdx].y ||
332
+ (bbox.cornersPx[i].y == bbox.cornersPx[topIdx].y &&
333
+ bbox.cornersPx[i].x < bbox.cornersPx[topIdx].x)) {
334
+ topIdx = i;
335
+ }
336
+ }
337
+ const int anchorX = bbox.cornersPx[topIdx].x;
338
+ const int anchorY = bbox.cornersPx[topIdx].y;
339
+
340
+ const int textX = anchorX + 2;
341
+ const int textY = anchorY - 3;
312
342
 
313
- // Always draw background rectangle above the box (full opacity)
343
+ // Draw axis-aligned label background above the topmost corner
314
344
  if (labelBackground) {
315
- // Pre-calculate and clamp coordinates
316
- const int bgX1 = std::max(0, bbox.boundingRect.x);
317
- const int bgY1 = std::max(0, bbox.boundingRect.y - bbox.textSize.height - 6);
318
- const int bgX2 = std::min(result.cols - 1, bbox.boundingRect.x + bbox.textSize.width + 4);
319
- const int bgY2 = std::min(result.rows - 1, bbox.boundingRect.y - 1);
345
+ const int bgX1 = std::max(0, anchorX);
346
+ const int bgY1 = std::max(0, anchorY - bbox.textSize.height - 6);
347
+ const int bgX2 = std::min(result.cols - 1, anchorX + bbox.textSize.width + 4);
348
+ const int bgY2 = std::min(result.rows - 1, anchorY - 1);
320
349
 
321
- // Full opacity background with bbox color
322
350
  cv::rectangle(result, cv::Point(bgX1, bgY1), cv::Point(bgX2, bgY2), bbox.bgrColor, cv::FILLED);
323
351
  }
324
352
 
325
- // Draw text with faster LINE_8 instead of LINE_AA
326
353
  cv::Scalar textColor = labelBackground ? cv::Scalar(0, 0, 0) : bbox.bgrColor;
327
354
  cv::putText(result, bbox.labelText, cv::Point(textX, textY), fontFace, fontScale, textColor, fontThickness, cv::LINE_8);
328
355
  }