justadudewhohacks / face-recognition.js

Simple Node.js package for robust face detection and face recognition. JavaScript and TypeScript API.
MIT License
1.91k stars 278 forks source link

face-detector img with no face error handling #60

Open zurek11 opened 6 years ago

zurek11 commented 6 years ago

Hi if i take a photo without any face is some way to handle this error with face detection? If so how can i handle this error? Because when i tried do that program returned this error:

fr.saveImage(path,faceImage[0]);
   ^

Error: Save_Image - Error: expected argument 1 to be of type ImageRGB
zurek11 commented 6 years ago

And one more question. How can i save recogniser with added faces to database? Is there some way to save this variable there? (Because I want to use prediction more time and is non effective to train recognizer again and again with the same images).

justadudewhohacks commented 6 years ago

Hi, if no faces are detected then the returned faceImages array is empty. In you case faceImage[0] is simply undefined I guess.

How to serialize a model to json and load it again is described in the readme:

Save a trained model to json file:

const fs = require('fs')
const modelState = recognizer.serialize()
fs.writeFileSync('model.json', JSON.stringify(modelState))

Load a trained model from json file:

const modelState = require('model.json')
recognizer.load(modelState)

Simply serialize the model and store the json object or the stringified json in your db.

zurek11 commented 6 years ago

const modelState = require('model.json') throws error: Cannot find module 'model.json' how can i install him? I was trying to install him as face-recognition so npm install model.json but console throw also error:

npm ERR! code E404
npm ERR! 404 Not Found: model.json@latest
justadudewhohacks commented 6 years ago

model.json is just a json file that you write the serialized state of the face recognizer to, as shown in the example above.

odykyi commented 6 years ago

@zurek11

// file1.js

const fs = require('fs')
// init recognizer
const modelState = recognizer.serialize()
fs.writeFileSync('model.json', JSON.stringify(modelState))

// file2.js

const modelState = require('./model.json');
//init recognizer
recognizer.load(modelState)