问题
I tried the following to load an image from disk using face-api.js:
faceapi.fetchImage(path.resolve(INPUT_DIR, 'input1.jpg');
It throws the following error: Error: fetch - missing fetch implementation for nodejs environment
Is there any other way of load image from disk and displaying using nodejs?
回答1:
The reason it fails because you need to implements the fetch function for it to work. FetchImage
should be used when you are trying to retrieve the image from online. If you are using the image from local disk, then do this:
Load the modules from local disk.
await faceapi.nets.ssdMobilenetv1.loadFromDisk(path.join(__dirname, 'models'));
// for me, I have put all the modules in src/models/
Load the canvas
Pass the canvas and modules option (if any)
let detectionresult = awaitfaceapi.detectAllFaces(canvas, this.getSSNMobileOptions())
来源:https://stackoverflow.com/questions/53685344/face-api-js-load-image-file-from-disk