V
V
Victor Nasonov2018-03-28 15:50:41
Node.js
Victor Nasonov, 2018-03-28 15:50:41

What did I do wrong (Face-recognition node js)?

put the package https://www.npmjs.com/package/face-recognition
train the model and save it

const fr = require('face-recognition') 
 const image = fr.loadImage('./image.jpeg')
 const detector = fr.FaceDetector()
 const faceImages = detector.detectFaces(image)
 //console.log(faceImages)
 const recognizer = fr.FaceRecognizer()
 recognizer.addFaces(faceImages, 'viktor')
 const fs = require('fs')
 const modelState = recognizer.serialize()
 fs.writeFileSync('model.json', JSON.stringify(modelState))
 fr.hitEnterToContinue()

comment code above add new
upload and recognize
const fr = require('face-recognition') 
 const image = fr.loadImage('./image.jpeg')
 const modelState = require('./model.json')
 console.log(modelState)
 const recognizer = fr.FaceRecognizer()
 recognizer.load(modelState)
 const predictions = recognizer.predict(image)
 console.log(predictions)

const detector = new fr.FrontalFaceDetector()
 //const predictor = fr.FaceLandmark5Predictor()
 const predictor = fr.FaceLandmark68Predictor()
 const img = fr.loadImage('./image.jpeg')
 const faceRects = detector.detect(img)
 const shapes = faceRects.map(rect => predictor.predict(img, rect))
 console.log(shapes)
 const win = new fr.ImageWindow()
 win.setImage(img)
 win.renderFaceDetections(shapes)
 fr.hitEnterToContinue()

outputs in the console and shows a photo
[ { className: 'viktor', faceDescriptors: [ [Array] ] } ]
[ { className: 'viktor', distance: 1.21 } ]
[ FullObjectDetection {
numParts: 68,
rect: Rect { area: 11025 , bottom: 158, top: 54, right: 227, left: 123 } } ]
leave the code block and change the image to an image with a white background (all white)
const fr = require('face-recognition') 
 const image = fr.loadImage('./image.jpeg')
 const modelState = require('./model.json')
 console.log(modelState)
 const recognizer = fr.FaceRecognizer()
 recognizer.load(modelState)
 const predictions = recognizer.predict(image)
 console.log(predictions)
 
 const detector = new fr.FrontalFaceDetector()
 //const predictor = fr.FaceLandmark5Predictor()
 const predictor = fr.FaceLandmark68Predictor()
 const img = fr.loadImage('./image.jpeg')
 const faceRects = detector.detect(img)
 const shapes = faceRects.map(rect => predictor.predict(img, rect))
 console.log(shapes)
 const win = new fr.ImageWindow()
 win.setImage(img)
 win.renderFaceDetections(shapes)
 fr.hitEnterToContinue()

produces
[ { className: 'viktor', faceDescriptors: [ [Array] ] } ]
[ { className: 'viktor', distance: 1.33 } ]
[]
Does the empty array at the end mean that the face is not recognized?
I can’t figure out what exactly recognizes my face, which is in
model.json
distance
What am I doing wrong?
I found examples but I don't know how to run them and I don't understand the code well
https://github.com/justadudewhohacks/face-recognit...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question