-
Notifications
You must be signed in to change notification settings - Fork 11
/
deepstack-face-recognition.html
221 lines (203 loc) · 9.88 KB
/
deepstack-face-recognition.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<script type="text/javascript">
RED.nodes.registerType('deepstack-face-recognition',{
category: 'function',
color: '#4682b4',
defaults: {
name: {value:""},
server: {value:"", type:"deepstack-server"},
confidence: {value: 80,required:true,validate:RED.validators.number()},
drawPredictions: {value: false},
outlineColor: {value: 'pink'},
filters: {value:[]},
outputs: {value:1}
},
inputs:1,
outputs:1,
outputLabels: function(index) {
let label = "";
if (index == 0) {
label = 'All Predictions';
} else {
label = 'Filter: ' + this.filters[index-1];
}
return label;
},
icon: "font-awesome/fa-user",
label: function() {
return this.name||"Face Recognition";
},
oneditprepare: function() {
var node = this;
var outputCount = $("#node-input-outputs").val("{\"0\":0}");
function resizeRule(rule) {
var newWidth = rule.width();
var valueField = rule.find(".node-input-filter-value");
valueField.typedInput("width",(newWidth-70));
}
$("#node-input-filter-container").css('min-height','150px').css('min-width','450px').editableList({
addItem: function(container,i,opt) {
container.css({
overflow: 'hidden',
whiteSpace: 'nowrap'
});
if (!opt.hasOwnProperty('i')) {
opt._i = Math.floor((0x99999-0x10000)*Math.random()).toString();
}
var row = $('<div/>').appendTo(container);
$('<input/>',{class:"node-input-filter-value",type:"text",style:"margin-left: 5px;"}).appendTo(row).typedInput({default:'str',types:['str']}).typedInput('value',opt.v);
var finalspan = $('<span/>',{style:"float: right;margin-top: 6px;"}).appendTo(row);
finalspan.append(' → <span class="node-input-filter-index">'+(i+2)+'</span> ');
var currentOutputs = JSON.parse(outputCount.val()||"{}");
currentOutputs[opt.hasOwnProperty('i')?opt.i:opt._i] = i+1;
outputCount.val(JSON.stringify(currentOutputs));
},
removeItem: function(opt) {
var currentOutputs = JSON.parse(outputCount.val()||"{}");
if (opt.hasOwnProperty('i')) {
currentOutputs[opt.i] = -1;
} else {
delete currentOutputs[opt._i];
}
var rules = $("#node-input-filter-container").editableList('items');
rules.each(function(i) {
$(this).find(".node-input-filter-index").html(i+1);
var data = $(this).data('data');
currentOutputs[data.hasOwnProperty('i')?data.i:data._i] = i+1;
});
outputCount.val(JSON.stringify(currentOutputs));
},
resizeItem: resizeRule,
sortItems: function(opt) {
var currentOutputs = JSON.parse(outputCount.val()||"{}");
var filters = $("#node-input-filter-container").editableList('items');
filters.each(function(i) {
$(this).find(".node-input-filter-index").html(i+1);
var data = $(this).data('data');
currentOutputs[data.hasOwnProperty('i')?data.i:data._i] = i+1;
});
outputCount.val(JSON.stringify(currentOutputs));
},
sortable: true,
removable: true
});
for (var i=0;i<this.filters.length;i++) {
var filter = this.filters[i];
$("#node-input-filter-container").editableList('addItem',{v: filter, i: i+1});
}
if (! $("#node-input-drawPredictions").is(":checked")) {
$("#row-outlineColor").hide();
$("#row-printLabel").hide();
}
$("#node-input-drawPredictions").click(function() {
$("#row-outlineColor").toggle(this.checked);
$("#row-printLabel").toggle(this.checked);
});
},
oneditsave: function() {
var filters = $("#node-input-filter-container").editableList('items');
var node = this;
node.filters = [];
filters.each(function(i) {
var value = $(this).find(".node-input-filter-value").typedInput('value');
node.filters.push(value);
});
this.propertyType = $("#node-input-property").typedInput('type');
},
oneditresize: function(size) {
var rows = $("#dialog-form>div:not(.node-input-filter-container-row)");
var height = size.height;
for (var i=0;i<rows.length;i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-filter-container-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
height += 16;
$("#node-input-filter-container").editableList('height',height);
}
});
</script>
<script type="text/x-red" data-template-name="deepstack-face-recognition">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
</div>
<div class="form-row">
<label for="node-input-server"><i class="icon-tag"></i> Deepstack server</label>
<input type="text" id="node-input-server">
</div>
<hr />
<div class="form-row">
<label for="node-input-confidence"><i class="icon-tag"></i> Minimum Confidence (%)</label>
<input type="text" id="node-input-confidence" size="5">
</div>
<div class="form-row">
<input type="checkbox" id="node-input-rejectUnauthorized" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-rejectUnauthorized" style="width: 90%;">Reject unauthorized</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-drawPredictions" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-drawPredictions" style="width: 90%;">Draw prediction outlines</label>
</div>
<div class="form-row" id="row-outlineColor" style="padding-left:10%;">
<label for="node-input-outlineColor"><i class="icon-tag"></i> Outline color</label>
<input type="text" id="node-input-outlineColor">
</div>
<div class="form-row" id="row-printLabel" style="padding-left:10%;">
<input type="checkbox" id="node-input-printLabel" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-printLabel" style="width: 90%;">Print prediction label</label>
</div>
<div class="form-row">
<hr />
<p>Filter output</p>
<input type="hidden" id="node-input-outputs"/>
</div>
<div class="form-row node-input-filter-container-row">
<ol id="node-input-filter-container"></ol>
</div>
</script>
<script type="text/x-red" data-help-name="deepstack-face-recognition">
<p>A node to query the Deepstack Object Detection API.</p>
<h3>Inputs</h3>
<p>The node takes one single input, the image to be processed.</p>
<dl class="message-properties">
<dt>payload
<span class="property-type">buffer</span>
</dt>
<dd> the image buffer to process. </dd>
</dl>
<h3>Outputs</h3>
<p>One or several outputs can be configured for this node. The default first output is always all predictions.
If desired, additional outputs can be configured, filtering the predictions.</p>
<ol class="node-ports">
<li>Standard output
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>Deepstack Object Detection predictions.</dd>
<dt>success <span class="property-type">boolean</span></dt>
<dd>Deepstack Object Detection status.</dd>
<dt>originalImage <span class="property-type">buffer</span></dt>
<dd>the image buffer processed.</dd>
<dt>outlinedImage <span class="property-type">buffer</span></dt>
<dd>the image buffer with rectangular outline around detected objects. Only if config option *drawPredictions* is true.</dd>
</dl>
</li>
<li>Filtered output
<dl class="message-properties">
<dt>payload <span class="property-type">object</span></dt>
<dd>Deepstack Object Detection predictions.</dd>
<dt>success <span class="property-type">boolean</span></dt>
<dd>Deepstack Object Detection status.</dd>
<dt>originalImage <span class="property-type">buffer</span></dt>
<dd>the image buffer processed.</dd>
<dt>outlinedImage <span class="property-type">buffer</span></dt>
<dd>the image buffer with rectangular outline around detected objects. Only if config option *drawPredictions* is true.</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>Sends an image to the Deepstack Object Detection API and outputs the predictions.</p>
<h3>References</h3>
<ul>
<li><a href="https://deepstack.cc/">Deepstack</a> - the service performing the actual magic.</li>
</ul>
</script>