@rosepetal/node-red-contrib-image-tools 1.1.3
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/.gitattributes +6 -0
- package/.github/workflows/build-prebuild.yml +326 -0
- package/LICENSE +13 -0
- package/README.md +161 -0
- package/artifacts/darwin-arm64/package.json +25 -0
- package/artifacts/linux-arm64/package.json +26 -0
- package/artifacts/linux-x64/package.json +26 -0
- package/artifacts/linuxmusl-x64/package.json +26 -0
- package/assets/flow_time_example.gif +0 -0
- package/assets/nodes/io/array-in-demo.gif +0 -0
- package/assets/nodes/io/array-out-demo.gif +0 -0
- package/assets/nodes/io/array-select-demo.gif +0 -0
- package/assets/nodes/io/image-in-demo.gif +0 -0
- package/assets/nodes/mix/concat-demo.gif +0 -0
- package/assets/nodes/mix/mosaic-demo.gif +0 -0
- package/assets/nodes/transform/crop-demo.gif +0 -0
- package/assets/nodes/transform/filter-demo.gif +0 -0
- package/assets/nodes/transform/padding-demo.gif +0 -0
- package/assets/nodes/transform/resize-demo.gif +0 -0
- package/assets/nodes/transform/rotate-demo.gif +0 -0
- package/docs/nodes/blend/add-mask.md +275 -0
- package/docs/nodes/blend/add-masks.md +284 -0
- package/docs/nodes/blend/blend.md +248 -0
- package/docs/nodes/io/array-in.md +119 -0
- package/docs/nodes/io/array-out.md +150 -0
- package/docs/nodes/io/array-select.md +157 -0
- package/docs/nodes/io/image-in.md +131 -0
- package/docs/nodes/io/image-out.md +179 -0
- package/docs/nodes/io/queue.md +57 -0
- package/docs/nodes/io/save-file.md +30 -0
- package/docs/nodes/mix/advanced-mosaic.md +108 -0
- package/docs/nodes/mix/concat.md +127 -0
- package/docs/nodes/mix/mosaic.md +146 -0
- package/docs/nodes/specialized/cropBB.md +271 -0
- package/docs/nodes/specialized/image-align.md +426 -0
- package/docs/nodes/transform/crop.md +132 -0
- package/docs/nodes/transform/draw.md +77 -0
- package/docs/nodes/transform/filter.md +84 -0
- package/docs/nodes/transform/padding.md +133 -0
- package/docs/nodes/transform/resize.md +158 -0
- package/docs/nodes/transform/rotate.md +121 -0
- package/docs/nodes/util/block-detect.md +46 -0
- package/install.sh +144 -0
- package/node-red-contrib-image-tools/lib/cpp-bridge.js +224 -0
- package/node-red-contrib-image-tools/lib/node-utils.js +529 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +590 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +241 -0
- package/node-red-contrib-image-tools/nodes/blend/add-mask.html +449 -0
- package/node-red-contrib-image-tools/nodes/blend/add-mask.js +170 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.html +703 -0
- package/node-red-contrib-image-tools/nodes/blend/add-masks.js +321 -0
- package/node-red-contrib-image-tools/nodes/blend/blend.html +552 -0
- package/node-red-contrib-image-tools/nodes/blend/blend.js +124 -0
- package/node-red-contrib-image-tools/nodes/io/array-in.html +110 -0
- package/node-red-contrib-image-tools/nodes/io/array-in.js +113 -0
- package/node-red-contrib-image-tools/nodes/io/array-out.html +125 -0
- package/node-red-contrib-image-tools/nodes/io/array-out.js +213 -0
- package/node-red-contrib-image-tools/nodes/io/array-select.html +156 -0
- package/node-red-contrib-image-tools/nodes/io/array-select.js +187 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.html +248 -0
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +335 -0
- package/node-red-contrib-image-tools/nodes/io/image-in.html +146 -0
- package/node-red-contrib-image-tools/nodes/io/image-in.js +143 -0
- package/node-red-contrib-image-tools/nodes/io/image-out.html +506 -0
- package/node-red-contrib-image-tools/nodes/io/image-out.js +545 -0
- package/node-red-contrib-image-tools/nodes/io/queue.html +119 -0
- package/node-red-contrib-image-tools/nodes/io/queue.js +191 -0
- package/node-red-contrib-image-tools/nodes/io/save-file.html +243 -0
- package/node-red-contrib-image-tools/nodes/io/save-file.js +440 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +2149 -0
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +195 -0
- package/node-red-contrib-image-tools/nodes/mix/concat.html +390 -0
- package/node-red-contrib-image-tools/nodes/mix/concat.js +112 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.html +550 -0
- package/node-red-contrib-image-tools/nodes/mix/mosaic.js +151 -0
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +268 -0
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +277 -0
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +528 -0
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +306 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.html +410 -0
- package/node-red-contrib-image-tools/nodes/transform/crop.js +149 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.html +719 -0
- package/node-red-contrib-image-tools/nodes/transform/draw.js +509 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.html +578 -0
- package/node-red-contrib-image-tools/nodes/transform/filter.js +177 -0
- package/node-red-contrib-image-tools/nodes/transform/padding.html +475 -0
- package/node-red-contrib-image-tools/nodes/transform/padding.js +142 -0
- package/node-red-contrib-image-tools/nodes/transform/resize.html +429 -0
- package/node-red-contrib-image-tools/nodes/transform/resize.js +162 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.html +299 -0
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +141 -0
- package/node-red-contrib-image-tools/nodes/util/block-detect.html +85 -0
- package/node-red-contrib-image-tools/nodes/util/block-detect.js +136 -0
- package/node-red-contrib-image-tools/nodes/util/clean-debug.html +201 -0
- package/node-red-contrib-image-tools/nodes/util/clean-debug.js +393 -0
- package/node-red-contrib-image-tools/package.json +64 -0
- package/npm/darwin-arm64/lib/.gitkeep +1 -0
- package/npm/darwin-arm64/package.json +25 -0
- package/npm/darwin-x64/lib/.gitkeep +1 -0
- package/npm/darwin-x64/package.json +25 -0
- package/npm/linux-arm64/lib/.gitkeep +1 -0
- package/npm/linux-arm64/package.json +26 -0
- package/npm/linux-x64/lib/.gitkeep +1 -0
- package/npm/linux-x64/package.json +26 -0
- package/npm/linuxmusl-x64/lib/.gitkeep +1 -0
- package/npm/linuxmusl-x64/package.json +26 -0
- package/npm/win32-x64/lib/.gitkeep +1 -0
- package/npm/win32-x64/package.json +25 -0
- package/package.json +74 -0
- package/rosepetal-image-engine/binding.gyp +153 -0
- package/rosepetal-image-engine/package.json +19 -0
- package/rosepetal-image-engine/src/add-bbs.cpp +433 -0
- package/rosepetal-image-engine/src/add-mask.cpp +240 -0
- package/rosepetal-image-engine/src/add-masks.cpp +638 -0
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +740 -0
- package/rosepetal-image-engine/src/blend.cpp +200 -0
- package/rosepetal-image-engine/src/concat.cpp +329 -0
- package/rosepetal-image-engine/src/crop.cpp +139 -0
- package/rosepetal-image-engine/src/draw.cpp +414 -0
- package/rosepetal-image-engine/src/filter.cpp +230 -0
- package/rosepetal-image-engine/src/filters/kernels.h +171 -0
- package/rosepetal-image-engine/src/image-align.cpp +551 -0
- package/rosepetal-image-engine/src/main.cpp +36 -0
- package/rosepetal-image-engine/src/mosaic.cpp +373 -0
- package/rosepetal-image-engine/src/padding.cpp +124 -0
- package/rosepetal-image-engine/src/resize.cpp +210 -0
- package/rosepetal-image-engine/src/rotate.cpp +177 -0
- package/rosepetal-image-engine/src/utils.h +563 -0
- package/rosepetal-image-engine/test-formats.js +119 -0
- package/scripts/build-opencv-static.ps1 +166 -0
- package/scripts/build-opencv-static.sh +147 -0
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
<!-- nodes/blend/add-bbs.html -->
|
|
2
|
+
|
|
3
|
+
<script type="text/javascript">
|
|
4
|
+
RED.nodes.registerType('add-bbs',{
|
|
5
|
+
category:'RP Image',
|
|
6
|
+
color:'#DDA0DD',
|
|
7
|
+
icon:'font-awesome/fa-object-group',
|
|
8
|
+
defaults:{
|
|
9
|
+
name:{value:""},
|
|
10
|
+
imagePath:{value:"payload.image"}, imagePathType:{value:"msg"},
|
|
11
|
+
boxesPath:{value:"payload"}, boxesPathType:{value:"msg"},
|
|
12
|
+
outputPath:{value:"payload"},outputPathType:{value:"msg"},
|
|
13
|
+
outputFormat:{value:"raw"},
|
|
14
|
+
outputQuality:{value:90},
|
|
15
|
+
pngOptimize:{value:false},
|
|
16
|
+
// Debug configuration
|
|
17
|
+
debugEnabled:{value:false},
|
|
18
|
+
debugWidth:{value:200},
|
|
19
|
+
debugWidthType:{value:"num"},
|
|
20
|
+
// Display options
|
|
21
|
+
showClassName:{value:true},
|
|
22
|
+
showConfidence:{value:true},
|
|
23
|
+
onlyMapped:{value:false},
|
|
24
|
+
// Visual settings
|
|
25
|
+
boxThickness:{value:2},
|
|
26
|
+
fontSize:{value:0.5},
|
|
27
|
+
// Class color mappings
|
|
28
|
+
classColorMappings:{value:[]}
|
|
29
|
+
},
|
|
30
|
+
inputs:1,outputs:1,
|
|
31
|
+
label:function(){return this.name||"add-bbs";},
|
|
32
|
+
oneditprepare:function(){
|
|
33
|
+
const node = this;
|
|
34
|
+
let classMappingIndex = 0;
|
|
35
|
+
|
|
36
|
+
/* path typedInputs */
|
|
37
|
+
$("#node-input-imagePath").typedInput({
|
|
38
|
+
default:'msg',types:['msg','flow','global'],
|
|
39
|
+
typeField:"#node-input-imagePathType"});
|
|
40
|
+
$("#node-input-boxesPath").typedInput({
|
|
41
|
+
default:'msg',types:['msg','flow','global'],
|
|
42
|
+
typeField:"#node-input-boxesPathType"});
|
|
43
|
+
$("#node-input-outputPath").typedInput({
|
|
44
|
+
default:'msg',types:['msg','flow','global'],
|
|
45
|
+
typeField:"#node-input-outputPathType"});
|
|
46
|
+
|
|
47
|
+
/* Box thickness slider */
|
|
48
|
+
const $thicknessSlider = $("#node-input-boxThickness");
|
|
49
|
+
const $thicknessValue = $("#thickness-value");
|
|
50
|
+
|
|
51
|
+
function updateThicknessDisplay() {
|
|
52
|
+
const value = parseInt($thicknessSlider.val());
|
|
53
|
+
$thicknessValue.text(value + "px");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
$thicknessSlider.on("input", updateThicknessDisplay);
|
|
57
|
+
updateThicknessDisplay();
|
|
58
|
+
|
|
59
|
+
/* Font size slider */
|
|
60
|
+
const $fontSizeSlider = $("#node-input-fontSize");
|
|
61
|
+
const $fontSizeValue = $("#fontSize-value");
|
|
62
|
+
|
|
63
|
+
function updateFontSizeDisplay() {
|
|
64
|
+
const value = parseFloat($fontSizeSlider.val());
|
|
65
|
+
$fontSizeValue.text(value.toFixed(1));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
$fontSizeSlider.on("input", updateFontSizeDisplay);
|
|
69
|
+
updateFontSizeDisplay();
|
|
70
|
+
|
|
71
|
+
function updateQualityVisibility(){
|
|
72
|
+
const format = $("#node-input-outputFormat").val();
|
|
73
|
+
$("#quality-row").toggle(format === "jpg" || format === "webp");
|
|
74
|
+
$("#png-optimize-row").toggle(format === "png");
|
|
75
|
+
}
|
|
76
|
+
$("#node-input-outputFormat").on("change", updateQualityVisibility);
|
|
77
|
+
updateQualityVisibility();
|
|
78
|
+
|
|
79
|
+
// === Debug Display Logic ===
|
|
80
|
+
const debugCheckbox = $('#node-input-debugEnabled');
|
|
81
|
+
const debugWidthRow = $('#debug-width-row');
|
|
82
|
+
|
|
83
|
+
// Initialize debug width TypedInput
|
|
84
|
+
$("#node-input-debugWidth").typedInput({
|
|
85
|
+
default: 'num',
|
|
86
|
+
types: ['num', 'msg', 'flow', 'global'],
|
|
87
|
+
typeField: "#node-input-debugWidthType"
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Function to toggle debug width visibility
|
|
91
|
+
function updateDebugWidthVisibility() {
|
|
92
|
+
if (debugCheckbox.is(':checked')) {
|
|
93
|
+
debugWidthRow.show();
|
|
94
|
+
} else {
|
|
95
|
+
debugWidthRow.hide();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Initialize debug state on node open
|
|
100
|
+
updateDebugWidthVisibility();
|
|
101
|
+
|
|
102
|
+
// Handle debug checkbox changes
|
|
103
|
+
debugCheckbox.on('change', function() {
|
|
104
|
+
const enabled = this.checked;
|
|
105
|
+
updateDebugWidthVisibility();
|
|
106
|
+
// Store debug state for runtime access
|
|
107
|
+
$('#node-input-debugEnabled').data('debug-enabled', enabled);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// === Dynamic Class Color Mapping Logic (reused from add-masks) ===
|
|
111
|
+
|
|
112
|
+
// Initialize class mappings from saved config
|
|
113
|
+
function initializeClassMappings() {
|
|
114
|
+
const mappings = node.classColorMappings || [];
|
|
115
|
+
mappings.forEach(mapping => {
|
|
116
|
+
addClassMappingRow(mapping.className, mapping.color);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (mappings.length === 0) {
|
|
120
|
+
addClassMappingRow(); // Add one empty row by default
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Add new class mapping row
|
|
125
|
+
function addClassMappingRow(className = '', color = '#ff0000') {
|
|
126
|
+
const container = $('#class-mappings-container');
|
|
127
|
+
const index = classMappingIndex++;
|
|
128
|
+
|
|
129
|
+
const rowHtml = `
|
|
130
|
+
<div class="class-mapping-row" data-index="${index}" style="margin-bottom: 10px; display: flex; align-items: center;">
|
|
131
|
+
<input type="text" placeholder="Class name (e.g., person)"
|
|
132
|
+
class="class-name-input" value="${className}"
|
|
133
|
+
style="width: 200px; margin-right: 10px;">
|
|
134
|
+
<input type="color" class="class-color-input" value="${color}"
|
|
135
|
+
style="width: 60px; height: 30px; margin-right: 10px;">
|
|
136
|
+
<button type="button" class="remove-class-mapping editor-button"
|
|
137
|
+
style="margin-right: 10px;">
|
|
138
|
+
<i class="fa fa-trash"></i>
|
|
139
|
+
</button>
|
|
140
|
+
<span class="duplicate-warning" style="color: red; display: none; margin-right: 10px;">
|
|
141
|
+
⚠️ Duplicate
|
|
142
|
+
</span>
|
|
143
|
+
<span class="color-conflict-warning" style="color: orange; display: none;">
|
|
144
|
+
⚠️ Similar color
|
|
145
|
+
</span>
|
|
146
|
+
</div>
|
|
147
|
+
`;
|
|
148
|
+
|
|
149
|
+
container.append(rowHtml);
|
|
150
|
+
updateEventHandlers();
|
|
151
|
+
validateClassNames();
|
|
152
|
+
validateColors();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Remove class mapping row
|
|
156
|
+
function removeClassMappingRow(index) {
|
|
157
|
+
$(`.class-mapping-row[data-index="${index}"]`).remove();
|
|
158
|
+
validateClassNames();
|
|
159
|
+
validateColors();
|
|
160
|
+
|
|
161
|
+
// Ensure at least one row exists
|
|
162
|
+
if ($('.class-mapping-row').length === 0) {
|
|
163
|
+
addClassMappingRow();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Update event handlers for dynamic elements
|
|
168
|
+
function updateEventHandlers() {
|
|
169
|
+
// Remove existing handlers to prevent duplicates
|
|
170
|
+
$('.remove-class-mapping').off('click');
|
|
171
|
+
$('.class-name-input').off('input');
|
|
172
|
+
$('.class-color-input').off('change');
|
|
173
|
+
|
|
174
|
+
// Add class mapping button
|
|
175
|
+
$('#add-class-mapping').off('click').on('click', function() {
|
|
176
|
+
addClassMappingRow();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Remove class mapping button
|
|
180
|
+
$('.remove-class-mapping').on('click', function() {
|
|
181
|
+
const index = $(this).closest('.class-mapping-row').data('index');
|
|
182
|
+
removeClassMappingRow(index);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Class name validation
|
|
186
|
+
$('.class-name-input').on('input', function() {
|
|
187
|
+
validateClassNames();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// Color change validation
|
|
191
|
+
$('.class-color-input').on('change', function() {
|
|
192
|
+
validateColors();
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Validate class names for duplicates
|
|
197
|
+
function validateClassNames() {
|
|
198
|
+
const classNames = [];
|
|
199
|
+
const inputs = $('.class-name-input');
|
|
200
|
+
|
|
201
|
+
inputs.each(function() {
|
|
202
|
+
const value = $(this).val().trim();
|
|
203
|
+
const row = $(this).closest('.class-mapping-row');
|
|
204
|
+
const warning = row.find('.duplicate-warning');
|
|
205
|
+
|
|
206
|
+
if (value && classNames.includes(value)) {
|
|
207
|
+
warning.show();
|
|
208
|
+
} else {
|
|
209
|
+
warning.hide();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (value) classNames.push(value);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Validate colors for conflicts (similar colors)
|
|
217
|
+
function validateColors() {
|
|
218
|
+
const colors = [];
|
|
219
|
+
const inputs = $('.class-color-input');
|
|
220
|
+
|
|
221
|
+
inputs.each(function() {
|
|
222
|
+
const color = $(this).val();
|
|
223
|
+
const row = $(this).closest('.class-mapping-row');
|
|
224
|
+
const warning = row.find('.color-conflict-warning');
|
|
225
|
+
|
|
226
|
+
// Check for similar colors (simplified RGB distance)
|
|
227
|
+
const hasSimilar = colors.some(existingColor => {
|
|
228
|
+
return calculateColorDistance(color, existingColor) < 50; // Threshold for "similar"
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
if (hasSimilar) {
|
|
232
|
+
warning.show();
|
|
233
|
+
} else {
|
|
234
|
+
warning.hide();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
colors.push(color);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Calculate simple RGB distance between two hex colors
|
|
242
|
+
function calculateColorDistance(color1, color2) {
|
|
243
|
+
const rgb1 = hexToRgb(color1);
|
|
244
|
+
const rgb2 = hexToRgb(color2);
|
|
245
|
+
|
|
246
|
+
if (!rgb1 || !rgb2) return 255; // Max distance for invalid colors
|
|
247
|
+
|
|
248
|
+
return Math.sqrt(
|
|
249
|
+
Math.pow(rgb1.r - rgb2.r, 2) +
|
|
250
|
+
Math.pow(rgb1.g - rgb2.g, 2) +
|
|
251
|
+
Math.pow(rgb1.b - rgb2.b, 2)
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function hexToRgb(hex) {
|
|
256
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
257
|
+
return result ? {
|
|
258
|
+
r: parseInt(result[1], 16),
|
|
259
|
+
g: parseInt(result[2], 16),
|
|
260
|
+
b: parseInt(result[3], 16)
|
|
261
|
+
} : null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Initialize UI
|
|
265
|
+
initializeClassMappings();
|
|
266
|
+
},
|
|
267
|
+
oneditsave: function() {
|
|
268
|
+
// Save class color mappings when dialog is closed
|
|
269
|
+
const mappings = [];
|
|
270
|
+
$('.class-mapping-row').each(function() {
|
|
271
|
+
const className = $(this).find('.class-name-input').val().trim();
|
|
272
|
+
const color = $(this).find('.class-color-input').val();
|
|
273
|
+
|
|
274
|
+
if (className) { // Only save non-empty class names
|
|
275
|
+
mappings.push({ className, color });
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
this.classColorMappings = mappings;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// Debug image display renderer - shared across all image processing nodes
|
|
284
|
+
if (!window.debugImageRendererInitialized) {
|
|
285
|
+
window.debugImageRendererInitialized = true;
|
|
286
|
+
|
|
287
|
+
(function() {
|
|
288
|
+
var isSubscribed = false;
|
|
289
|
+
|
|
290
|
+
function subscribeToDebugImages() {
|
|
291
|
+
if (isSubscribed || typeof RED === 'undefined' || !RED.comms) return;
|
|
292
|
+
isSubscribed = true;
|
|
293
|
+
|
|
294
|
+
RED.comms.subscribe('debug-image', function(event, data) {
|
|
295
|
+
if (!data || !data.id) return;
|
|
296
|
+
|
|
297
|
+
try {
|
|
298
|
+
renderDebugImage(data);
|
|
299
|
+
} catch (err) {
|
|
300
|
+
console.warn('Debug image render error:', err);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function renderDebugImage(data) {
|
|
306
|
+
const nodeId = data.id;
|
|
307
|
+
const base64Data = data.data;
|
|
308
|
+
const format = data.format || 'unknown';
|
|
309
|
+
const mimeType = data.mimeType || 'jpeg';
|
|
310
|
+
|
|
311
|
+
if (!base64Data) {
|
|
312
|
+
removeDebugImage(nodeId);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const nodeElement = document.getElementById(nodeId);
|
|
317
|
+
if (!nodeElement) return;
|
|
318
|
+
|
|
319
|
+
let debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
320
|
+
|
|
321
|
+
if (!debugContainer) {
|
|
322
|
+
// Create SVG foreignObject to embed HTML content in SVG
|
|
323
|
+
debugContainer = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
|
|
324
|
+
debugContainer.id = 'debug-img-container-' + nodeId;
|
|
325
|
+
debugContainer.setAttribute('x', '70');
|
|
326
|
+
debugContainer.setAttribute('y', '5');
|
|
327
|
+
debugContainer.setAttribute('width', '120');
|
|
328
|
+
debugContainer.setAttribute('height', '120');
|
|
329
|
+
debugContainer.style.overflow = 'visible';
|
|
330
|
+
|
|
331
|
+
// Create simple image directly inside foreignObject
|
|
332
|
+
const img = document.createElement('img');
|
|
333
|
+
img.id = 'debug-img-' + nodeId;
|
|
334
|
+
img.style.width = '100%';
|
|
335
|
+
img.style.height = 'auto';
|
|
336
|
+
img.style.display = 'block';
|
|
337
|
+
img.style.cursor = 'pointer';
|
|
338
|
+
img.style.maxHeight = '100px';
|
|
339
|
+
img.style.maxWidth = '100px';
|
|
340
|
+
|
|
341
|
+
img.onclick = function() {
|
|
342
|
+
removeDebugImage(nodeId);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
debugContainer.appendChild(img);
|
|
346
|
+
nodeElement.appendChild(debugContainer);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const img = document.getElementById('debug-img-' + nodeId);
|
|
350
|
+
|
|
351
|
+
if (img) {
|
|
352
|
+
img.src = `data:image/${mimeType};base64,${base64Data}`;
|
|
353
|
+
img.title = 'Debug image (click to hide)';
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function removeDebugImage(nodeId) {
|
|
358
|
+
const debugContainer = document.getElementById('debug-img-container-' + nodeId);
|
|
359
|
+
if (debugContainer) {
|
|
360
|
+
debugContainer.remove();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function initializeWhenReady() {
|
|
365
|
+
if (typeof RED !== 'undefined' && RED.comms) {
|
|
366
|
+
subscribeToDebugImages();
|
|
367
|
+
|
|
368
|
+
// Clean up orphaned debug images periodically
|
|
369
|
+
setInterval(function() {
|
|
370
|
+
const debugContainers = document.querySelectorAll('[id^="debug-img-container-"]');
|
|
371
|
+
debugContainers.forEach(container => {
|
|
372
|
+
const nodeId = container.id.replace('debug-img-container-', '');
|
|
373
|
+
const nodeElement = document.getElementById(nodeId);
|
|
374
|
+
if (!nodeElement) {
|
|
375
|
+
container.remove();
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}, 5000);
|
|
379
|
+
} else {
|
|
380
|
+
setTimeout(initializeWhenReady, 100);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (document.readyState === 'loading') {
|
|
385
|
+
document.addEventListener('DOMContentLoaded', initializeWhenReady);
|
|
386
|
+
} else {
|
|
387
|
+
initializeWhenReady();
|
|
388
|
+
}
|
|
389
|
+
})();
|
|
390
|
+
}
|
|
391
|
+
</script>
|
|
392
|
+
|
|
393
|
+
<script type="text/x-red" data-template-name="add-bbs">
|
|
394
|
+
<div class="form-row">
|
|
395
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
396
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
397
|
+
</div>
|
|
398
|
+
|
|
399
|
+
<div class="form-row">
|
|
400
|
+
<label><i class="fa fa-picture-o"></i> Image</label>
|
|
401
|
+
<input type="text" id="node-input-imagePath" style="width:70%;">
|
|
402
|
+
<input type="hidden" id="node-input-imagePathType">
|
|
403
|
+
</div>
|
|
404
|
+
|
|
405
|
+
<div class="form-row">
|
|
406
|
+
<label><i class="fa fa-object-group"></i> Boxes Array</label>
|
|
407
|
+
<input type="text" id="node-input-boxesPath" style="width:70%;">
|
|
408
|
+
<input type="hidden" id="node-input-boxesPathType">
|
|
409
|
+
</div>
|
|
410
|
+
|
|
411
|
+
<div class="form-row">
|
|
412
|
+
<label><i class="fa fa-sign-out"></i> Output</label>
|
|
413
|
+
<input type="text" id="node-input-outputPath" style="width:70%;">
|
|
414
|
+
<input type="hidden" id="node-input-outputPathType">
|
|
415
|
+
</div>
|
|
416
|
+
|
|
417
|
+
<div class="form-row">
|
|
418
|
+
<label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
|
|
419
|
+
<select id="node-input-outputFormat" style="width: 200px;">
|
|
420
|
+
<option value="raw">Raw (fastest)</option>
|
|
421
|
+
<option value="jpg">JPEG</option>
|
|
422
|
+
<option value="png">PNG</option>
|
|
423
|
+
<option value="webp">WebP</option>
|
|
424
|
+
</select>
|
|
425
|
+
</div>
|
|
426
|
+
|
|
427
|
+
<div class="form-row" id="quality-row">
|
|
428
|
+
<label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
|
|
429
|
+
<input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
|
|
430
|
+
<span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
|
|
431
|
+
</div>
|
|
432
|
+
|
|
433
|
+
<div class="form-row" id="png-optimize-row" style="display: none;">
|
|
434
|
+
<label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
|
|
435
|
+
<input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
436
|
+
<label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
|
|
437
|
+
</div>
|
|
438
|
+
|
|
439
|
+
<!-- Debug Configuration -->
|
|
440
|
+
<div class="form-row">
|
|
441
|
+
<label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
|
|
442
|
+
<input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
|
|
443
|
+
<label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
|
|
444
|
+
</div>
|
|
445
|
+
<div class="form-row" id="debug-width-row" style="display: none;">
|
|
446
|
+
<label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
|
|
447
|
+
<input type="text" id="node-input-debugWidth" style="width: 120px;">
|
|
448
|
+
<input type="hidden" id="node-input-debugWidthType">
|
|
449
|
+
<span style="margin-left: 10px; color: #666;">pixels</span>
|
|
450
|
+
</div>
|
|
451
|
+
|
|
452
|
+
<hr/>
|
|
453
|
+
|
|
454
|
+
<!-- Display Options -->
|
|
455
|
+
<div class="form-row">
|
|
456
|
+
<label><i class="fa fa-eye"></i> Display Options</label>
|
|
457
|
+
<div style="margin-left: 105px;">
|
|
458
|
+
<input type="checkbox" id="node-input-showClassName" style="width:auto; display:inline-block; vertical-align:baseline;">
|
|
459
|
+
<label for="node-input-showClassName" style="width:auto;">Show Tag Name</label>
|
|
460
|
+
<br>
|
|
461
|
+
<input type="checkbox" id="node-input-showConfidence" style="width:auto; display:inline-block; vertical-align:baseline;">
|
|
462
|
+
<label for="node-input-showConfidence" style="width:auto;">Show Confidence</label>
|
|
463
|
+
<br>
|
|
464
|
+
<input type="checkbox" id="node-input-onlyMapped" style="width:auto; display:inline-block; vertical-align:baseline;">
|
|
465
|
+
<label for="node-input-onlyMapped" style="width:auto;">Only Draw Mapped Tags</label>
|
|
466
|
+
</div>
|
|
467
|
+
</div>
|
|
468
|
+
|
|
469
|
+
<hr/>
|
|
470
|
+
|
|
471
|
+
<!-- Visual Settings -->
|
|
472
|
+
<div class="form-row">
|
|
473
|
+
<label for="node-input-boxThickness"><i class="fa fa-square-o"></i> Box Thickness</label>
|
|
474
|
+
<input type="range" id="node-input-boxThickness" min="1" max="10" value="2" style="width:200px;">
|
|
475
|
+
<span id="thickness-value" style="margin-left: 10px; font-weight: bold;">2px</span>
|
|
476
|
+
</div>
|
|
477
|
+
|
|
478
|
+
<div class="form-row">
|
|
479
|
+
<label for="node-input-fontSize"><i class="fa fa-font"></i> Font Size</label>
|
|
480
|
+
<input type="range" id="node-input-fontSize" min="0.3" max="2.0" step="0.1" value="0.5" style="width:200px;">
|
|
481
|
+
<span id="fontSize-value" style="margin-left: 10px; font-weight: bold;">0.5</span>
|
|
482
|
+
</div>
|
|
483
|
+
|
|
484
|
+
<hr/>
|
|
485
|
+
|
|
486
|
+
<!-- Tag Color Mappings -->
|
|
487
|
+
<div class="form-row">
|
|
488
|
+
<label><i class="fa fa-palette"></i> Tag Color Mappings</label>
|
|
489
|
+
<div id="class-mappings-container" style="margin-top: 10px;">
|
|
490
|
+
<!-- Dynamic tag mapping rows will be inserted here -->
|
|
491
|
+
</div>
|
|
492
|
+
<div style="margin-top: 10px;">
|
|
493
|
+
<button type="button" id="add-class-mapping" class="editor-button">
|
|
494
|
+
<i class="fa fa-plus"></i> Add Tag Mapping
|
|
495
|
+
</button>
|
|
496
|
+
</div>
|
|
497
|
+
<div style="margin-top: 5px; font-size: 11px; color: #666;">
|
|
498
|
+
Define colors for specific tags. Undefined tags will automatically use maximally different colors.
|
|
499
|
+
</div>
|
|
500
|
+
</div>
|
|
501
|
+
|
|
502
|
+
<hr/>
|
|
503
|
+
|
|
504
|
+
</script>
|
|
505
|
+
|
|
506
|
+
<script type="text/x-red" data-help-name="add-bbs">
|
|
507
|
+
<p><b>rosepetal-add-bbs</b> draws bounding boxes with optional labels on images for object detection visualization. This node processes arrays of bounding box objects with automatic color assignment for different classes.</p>
|
|
508
|
+
|
|
509
|
+
<h3>Details</h3>
|
|
510
|
+
<p>This node performs high-performance bounding box rendering using OpenCV. Boxes are drawn from 4-corner coordinates (normalized 0-1 range) with customizable colors, thickness, and label display options. Labels can show class names, confidence scores, or both with configurable positioning and background.</p>
|
|
511
|
+
|
|
512
|
+
<h3>Properties</h3>
|
|
513
|
+
<dl class="message-properties">
|
|
514
|
+
<dt>Image <span class="property-type">string</span></dt>
|
|
515
|
+
<dd>Message property path containing the base image on which boxes will be drawn. Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
|
|
516
|
+
|
|
517
|
+
<dt>Boxes Array <span class="property-type">string</span></dt>
|
|
518
|
+
<dd>Message property path containing the boxes array. Expected structure: array of objects with <code>raw_boxes</code> coordinates (4 corners), <code>tag</code>, and optional <code>confidence</code>. Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
|
|
519
|
+
|
|
520
|
+
<dt>Output to <span class="property-type">string</span></dt>
|
|
521
|
+
<dd>Message property path where the image with drawn boxes will be stored. Supports <code>msg</code>, <code>flow</code>, or <code>global</code> context via TypedInput.</dd>
|
|
522
|
+
|
|
523
|
+
<dt>Output Format <span class="property-type">string</span></dt>
|
|
524
|
+
<dd>Format for the output image: <code>raw</code> (fastest), <code>jpg</code>, <code>png</code>, or <code>webp</code>.</dd>
|
|
525
|
+
|
|
526
|
+
<dt>Quality <span class="property-type">number</span></dt>
|
|
527
|
+
<dd>Compression quality (1-100) for JPEG and WebP formats. Only visible when JPG or WebP is selected.</dd>
|
|
528
|
+
|
|
529
|
+
<dt>Show Tag Name <span class="property-type">boolean</span></dt>
|
|
530
|
+
<dd>Display the tag name as part of the box label.</dd>
|
|
531
|
+
|
|
532
|
+
<dt>Show Confidence <span class="property-type">boolean</span></dt>
|
|
533
|
+
<dd>Display the confidence score as part of the box label (e.g., "95.4%").</dd>
|
|
534
|
+
|
|
535
|
+
<dt>Only Mapped Tags <span class="property-type">boolean</span></dt>
|
|
536
|
+
<dd>When enabled, only draw boxes for tags that have explicit color mappings defined.</dd>
|
|
537
|
+
|
|
538
|
+
<dt>Box Thickness <span class="property-type">number</span></dt>
|
|
539
|
+
<dd>Line thickness for bounding boxes (1-10 pixels).</dd>
|
|
540
|
+
|
|
541
|
+
<dt>Font Size <span class="property-type">number</span></dt>
|
|
542
|
+
<dd>Scale factor for label text (0.3-2.0).</dd>
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
<dt>Tag Color Mappings <span class="property-type">array</span></dt>
|
|
546
|
+
<dd>Dynamic list of tag name to color mappings. Each mapping defines a specific color for boxes with that tag.</dd>
|
|
547
|
+
</dl>
|
|
548
|
+
|
|
549
|
+
<h3>Input Structure</h3>
|
|
550
|
+
<p>The boxes array should follow this exact structure:</p>
|
|
551
|
+
<pre>[
|
|
552
|
+
{
|
|
553
|
+
"tag": "mountain",
|
|
554
|
+
"raw_boxes": [[x1,y1], [x2,y1], [x2,y2], [x1,y2]], // 4 corners, normalized [0,1]
|
|
555
|
+
"confidence": 0.98095703125
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
"tag": "bottle",
|
|
559
|
+
"raw_boxes": [[0.82,0.14], [0.93,0.14], [0.93,0.98], [0.82,0.98]],
|
|
560
|
+
"confidence": 0.96337890625
|
|
561
|
+
}
|
|
562
|
+
]</pre>
|
|
563
|
+
|
|
564
|
+
<h3>Key Features</h3>
|
|
565
|
+
<ul>
|
|
566
|
+
<li><b>4-Corner Box Format:</b> Normalized coordinates [0,1] for resolution-independent processing</li>
|
|
567
|
+
<li><b>Dynamic Color Management:</b> Add/remove tag color mappings with real-time validation</li>
|
|
568
|
+
<li><b>Auto-Color Generation:</b> Maximally different colors for undefined tags</li>
|
|
569
|
+
<li><b>Flexible Labels:</b> Show tag name, confidence, both, or neither</li>
|
|
570
|
+
<li><b>Smart Positioning:</b> Automatic adjustment when labels would go off-screen</li>
|
|
571
|
+
<li><b>Performance Optimized:</b> Direct pixel manipulation with OpenMP parallelization</li>
|
|
572
|
+
</ul>
|
|
573
|
+
|
|
574
|
+
<h3>Label Formatting</h3>
|
|
575
|
+
<p>Labels are formatted based on display options:</p>
|
|
576
|
+
<ul>
|
|
577
|
+
<li><b>Tag Only:</b> "mountain"</li>
|
|
578
|
+
<li><b>Confidence Only:</b> "98.1%"</li>
|
|
579
|
+
<li><b>Both:</b> "mountain (98.1%)"</li>
|
|
580
|
+
<li><b>Neither:</b> Box drawn without label</li>
|
|
581
|
+
</ul>
|
|
582
|
+
|
|
583
|
+
<h3>Performance</h3>
|
|
584
|
+
<ul>
|
|
585
|
+
<li><b>C++ Backend:</b> High-performance OpenCV implementation with optimizations</li>
|
|
586
|
+
<li><b>Direct Drawing:</b> Efficient rectangle and text rendering</li>
|
|
587
|
+
<li><b>Cached Colors:</b> Reuses color calculations across boxes</li>
|
|
588
|
+
<li><b>Parallel Processing:</b> OpenMP parallelization for multiple boxes</li>
|
|
589
|
+
</ul>
|
|
590
|
+
</script>
|