Closed juggledad closed 3 years ago
I am going to stick to the format produced by the face-api because it a dependency if somthing changes in it it may break code I make to change the behaviour you seek.
However you bring up a good point. That should be in the documentation.
I never thought about adding that to the documentation as I created a way to handle it in the advance flow example. with my function node.
you can just do a check to see if its an array
var Result = msg.payload.Result;
if ( Array.isArray(Result) ) {
//do stuff here if its an array
}
else {
//do stuff here if its not an array
}
//global vars
var the_rects;
//was detectAllFaces or detectSingleFace used
//check to see if payload.Result is an array (detectAllFaces)
var Result = msg.payload.Result;
if ( Array.isArray(Result) ) {
// get just the rect values and place in array
the_rects = Result.map(x => {
//check for label from FaceRecognition
var match_label;
if ( x.match ) {
match_label = x.match._label;
}
else {
match_label = "";
}
var result = {
type: "rect",
x: x.detection._box._x,
y: x.detection._box._y,
w: x.detection._box._width,
h: x.detection._box._height,
label: match_label
}
return result;
});
msg.annotations = the_rects;
}
//else detectSingleFace was used
else {
//check for label from FaceRecognition
var match_label;
if ( Result.match ) {
match_label = Result.match._label;
}
else {
match_label = "";
}
the_rects = [{
type: "rect",
x: Result.detection._box._x,
y: Result.detection._box._y,
w: Result.detection._box._width,
h: Result.detection._box._height,
label: match_label.match._label
}]
msg.annotations = the_rects;
}
msg.payload = msg.payload.OriginalBufferedImg;
return msg;
Added to documentation. Pushed to github, Will push update to npm / node-red when I have more corrections.
You can also use a switch node. Have one condition use the 'is type of' option - with the type 'array' and a second condition use the 'otherwise
Close issue: Keep current behaviour
Currently if Tasks = DetectSingleFace then Payload.Result returns an object but if Tasks = DetectAllFaces then Payload.Result returns an array
Always returning the result as an array would make it easier for following nodes to deal with the results
(I just spent an hour trying to figure out why my debug displaying
payload.Result[0].match._label
was coming up withunknown
when Tasks = DetectSingleFace)