node-red-contrib-facial-recognition
Advanced tools
Comparing version 0.24.88 to 0.25.89
@@ -301,8 +301,14 @@ //2020 David L Burrows | ||
{ | ||
const decoded = tf.node.decodeImage(buffer); | ||
const casted = decoded.toFloat(); | ||
const result = casted.expandDims(0); | ||
decoded.dispose(); | ||
casted.dispose(); | ||
return result; | ||
try { | ||
const decoded = tf.node.decodeImage(buffer); | ||
const casted = decoded.toFloat(); | ||
const result = casted.expandDims(0); | ||
decoded.dispose(); | ||
casted.dispose(); | ||
return result; | ||
} catch (error) { | ||
notify_user_errors(error); | ||
} | ||
} | ||
@@ -352,10 +358,19 @@ | ||
const face_detect_tensor = await image(bufferd_img); | ||
const detections = await faceapi.detectSingleFace(face_detect_tensor).withFaceLandmarks().withFaceDescriptor(); | ||
//make dang sure that a face was detected and a descriptor was created. | ||
//else a undefined value sent to the descriptions array causes new faceapi.LabeledFaceDescriptors(each_dir_name, descriptions); to fail | ||
if ( detections ) | ||
var detections; | ||
if ( face_detect_tensor ) | ||
{ | ||
if ( detections.descriptor ) | ||
detections = await faceapi.detectSingleFace(face_detect_tensor).withFaceLandmarks().withFaceDescriptor(); | ||
//make dang sure that a face was detected and a descriptor was created. | ||
//else a undefined value sent to the descriptions array causes new faceapi.LabeledFaceDescriptors(each_dir_name, descriptions); to fail | ||
if ( detections ) | ||
{ | ||
descriptions.push(detections.descriptor); | ||
if ( detections.descriptor ) | ||
{ | ||
descriptions.push(detections.descriptor); | ||
face_detect_tensor.dispose(); | ||
} | ||
} | ||
else | ||
{ | ||
notify_user_errors('Unable to create FaceDescriptor. Please replace this image with a face that can be found. Did not load this image ' + image_names_in_each_dir_name[i]); | ||
face_detect_tensor.dispose(); | ||
@@ -366,4 +381,3 @@ } | ||
{ | ||
notify_user_errors('Unable to create FaceDescriptor. Please replace this image with a face that can be found. Did not load this image ' + image_names_in_each_dir_name[i]); | ||
face_detect_tensor.dispose(); | ||
notify_user_errors('unable to decode file ' + image_names_in_each_dir_name[i]); | ||
} | ||
@@ -376,10 +390,19 @@ } | ||
const face_detect_tensor = await image(bufferd_img); | ||
const detections = await faceapi.detectSingleFace(face_detect_tensor).withFaceLandmarks().withFaceDescriptor(); | ||
//make dang sure that a face was detected and a descriptor was created. | ||
//else a undefined value sent to the descriptions array causes new faceapi.LabeledFaceDescriptors(each_dir_name, descriptions); to fail | ||
if ( detections ) | ||
var detections; | ||
if ( face_detect_tensor ) | ||
{ | ||
if ( detections.descriptor ) | ||
detections = await faceapi.detectSingleFace(face_detect_tensor).withFaceLandmarks().withFaceDescriptor(); | ||
//make dang sure that a face was detected and a descriptor was created. | ||
//else a undefined value sent to the descriptions array causes new faceapi.LabeledFaceDescriptors(each_dir_name, descriptions); to fail | ||
if ( detections ) | ||
{ | ||
descriptions.push(detections.descriptor); | ||
if ( detections.descriptor ) | ||
{ | ||
descriptions.push(detections.descriptor); | ||
face_detect_tensor.dispose(); | ||
} | ||
} | ||
else | ||
{ | ||
notify_user_errors('Unable to create FaceDescriptor. Please replace this image with a face that can be found. Did not load this image ' + image_names_in_each_dir_name[i]); | ||
face_detect_tensor.dispose(); | ||
@@ -390,4 +413,3 @@ } | ||
{ | ||
notify_user_errors('Unable to create FaceDescriptor. Please replace this image with a face that can be found. Did not load this image ' + image_names_in_each_dir_name[i]); | ||
face_detect_tensor.dispose(); | ||
notify_user_errors('unable to decode file ' + image_names_in_each_dir_name[i]); | ||
} | ||
@@ -660,8 +682,6 @@ } | ||
// load image from payload | ||
const tensor = await image(img).catch(error => { | ||
notify_user_errors("Input Buffer " + error); | ||
}); | ||
const tensor = await image(img); | ||
///////////////////////////////////////////////////////////////// | ||
@@ -749,88 +769,95 @@ // add check image size for inputs mabye if too large??? hold off on this | ||
//msg.model_eval = model_eval; | ||
var result; | ||
try { | ||
// actual model execution for image send via msg payload | ||
result = await eval(model_eval); | ||
} | ||
catch (error) | ||
if ( tensor ) | ||
{ | ||
try { | ||
// actual model execution for image send via msg payload | ||
result = await eval(model_eval); | ||
} | ||
catch (error) | ||
{ | ||
notify_user_errors(error); | ||
} | ||
//var result = await eval(model_eval); | ||
//garbage colletion | ||
tensor.dispose(); | ||
tensor.dispose(); | ||
//check if user wants to do Face_Recognition | ||
//FaceRecognition for node set via node properties | ||
if ( this.Face_Recognition === 'Face_Recognition_enabled' ) | ||
{ | ||
//error check that withFaceDescriptor(s) must be enabled to use FaceRecognition | ||
if ( this.FaceDescriptors === false || this.FaceLandmarks === false ) | ||
//check if user wants to do Face_Recognition | ||
//FaceRecognition for node set via node properties | ||
if ( this.Face_Recognition === 'Face_Recognition_enabled' ) | ||
{ | ||
notify_user_errors('FaceRecognition Error: must enable withFaceDescriptor(s) and withFaceLandmarks to use FaceRecognition'); | ||
//send what was done | ||
} | ||
else | ||
{ | ||
//see if user wants to ReInitializeFaceMatcher | ||
const context_FaceMatcherInitialized = nodeContext.get('FaceMatcherInitialized') || false; | ||
//context_previous_faceMatcher false or context_FaceMatcherInitialized | ||
if ( context_previous_faceMatcher === false || context_FaceMatcherInitialized === false ) | ||
//error check that withFaceDescriptor(s) must be enabled to use FaceRecognition | ||
if ( this.FaceDescriptors === false || this.FaceLandmarks === false ) | ||
{ | ||
//check if example path else use user defined dirPath | ||
var user_path; | ||
if ( this.Face_Recognition_enabled_path === '/example/labeled_face' ) | ||
notify_user_errors('FaceRecognition Error: must enable withFaceDescriptor(s) and withFaceLandmarks to use FaceRecognition'); | ||
//send what was done | ||
} | ||
else | ||
{ | ||
//see if user wants to ReInitializeFaceMatcher | ||
const context_FaceMatcherInitialized = nodeContext.get('FaceMatcherInitialized') || false; | ||
//context_previous_faceMatcher false or context_FaceMatcherInitialized | ||
if ( context_previous_faceMatcher === false || context_FaceMatcherInitialized === false ) | ||
{ | ||
user_path = path.join(__dirname, '/example/labeled_face'); | ||
} | ||
else | ||
{ | ||
user_path = this.Face_Recognition_enabled_path; | ||
} | ||
var list_dirs_in_labeled_face_folder = await listDirectories(user_path).catch(error => { | ||
notify_user_errors(error); | ||
}); | ||
//msg.dirs = list_dirs_in_labeled_face_folder; | ||
//check if example path else use user defined dirPath | ||
var user_path; | ||
if ( this.Face_Recognition_enabled_path === '/example/labeled_face' ) | ||
{ | ||
user_path = path.join(__dirname, '/example/labeled_face'); | ||
} | ||
else | ||
{ | ||
user_path = this.Face_Recognition_enabled_path; | ||
} | ||
var list_dirs_in_labeled_face_folder = await listDirectories(user_path).catch(error => { | ||
notify_user_errors(error); | ||
}); | ||
//msg.dirs = list_dirs_in_labeled_face_folder; | ||
// get just the names of the dirs | ||
var list_dirs_in_labeled_face_folder_names_only = list_dirs_in_labeled_face_folder.map(x => { | ||
var n = x.lastIndexOf('/'); | ||
var result = x.substring(n + 1); | ||
return result; | ||
}); | ||
//msg.dirs_names_only =list_dirs_in_labeled_face_folder_names_only; | ||
// get just the names of the dirs | ||
var list_dirs_in_labeled_face_folder_names_only = list_dirs_in_labeled_face_folder.map(x => { | ||
var n = x.lastIndexOf('/'); | ||
var result = x.substring(n + 1); | ||
return result; | ||
}); | ||
//msg.dirs_names_only =list_dirs_in_labeled_face_folder_names_only; | ||
const labeledFaceDescriptors = await LoadLabeledImages(); | ||
//msg.labeledFaceDescriptors = labeledFaceDescriptors; | ||
const labeledFaceDescriptors = await LoadLabeledImages(); | ||
//msg.labeledFaceDescriptors = labeledFaceDescriptors; | ||
const faceMatcher = new faceapi.FaceMatcher(labeledFaceDescriptors, this.Face_Recognition_distanceThreshold); | ||
nodeContext.set('faceMatcher',faceMatcher); | ||
nodeContext.set('FaceMatcherInitialized',true); | ||
//msg.faceMatcher = faceMatcher; | ||
} | ||
var faceMatcher = nodeContext.get('faceMatcher'); | ||
const faceMatcher = new faceapi.FaceMatcher(labeledFaceDescriptors, this.Face_Recognition_distanceThreshold); | ||
nodeContext.set('faceMatcher',faceMatcher); | ||
nodeContext.set('FaceMatcherInitialized',true); | ||
//msg.faceMatcher = faceMatcher; | ||
} | ||
var faceMatcher = nodeContext.get('faceMatcher'); | ||
//sort detections single/multiple faces | ||
if ( this.Tasks === 'detectAllFaces' ) | ||
{ | ||
result = result.map(fd => { | ||
const the_object = fd; | ||
//add the match to the object | ||
the_object.match = faceMatcher.findBestMatch(fd.descriptor); | ||
//sort detections single/multiple faces | ||
if ( this.Tasks === 'detectAllFaces' ) | ||
{ | ||
result = result.map(fd => { | ||
const the_object = fd; | ||
//add the match to the object | ||
the_object.match = faceMatcher.findBestMatch(fd.descriptor); | ||
return the_object; | ||
}); | ||
return the_object; | ||
}); | ||
} | ||
if ( this.Tasks === 'detectSingleFace' ) | ||
{ | ||
result.match = faceMatcher.findBestMatch(result.descriptor); | ||
} | ||
} | ||
if ( this.Tasks === 'detectSingleFace' ) | ||
{ | ||
result.match = faceMatcher.findBestMatch(result.descriptor); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
notify_user_errors("Input Error: buffered imagae sent is not of valid type. Please send a valid image"); | ||
} | ||
} | ||
//time to complete process | ||
@@ -837,0 +864,0 @@ const time_elap_millis = Date.now() - start; |
{ | ||
"name": "node-red-contrib-facial-recognition", | ||
"version": "0.24.88", | ||
"version": "0.25.89", | ||
"description": "Provides a node-red node for password validation; checks that a password meets your defined requierments.", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -256,2 +256,9 @@ | ||
<br> | ||
version 0.25.89 - bug - UnhandledPromiseRejection - added catch to handle these | ||
<br> | ||
<br> | ||
<br> | ||
version 0.25.88 - added error checks for user submiting bad/unkown images to the folder or as msg.input | ||
<br> | ||
<br> | ||
version 0.24.88 - typo fix in documentation | ||
@@ -258,0 +265,0 @@ <br> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20267970
845
278