face-api.js load image file from disk

2019-08-17 06:43发布

问题:

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:

  1. 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/

  2. Load the canvas

  3. Pass the canvas and modules option (if any)

    let detectionresult = awaitfaceapi.detectAllFaces(canvas, this.getSSNMobileOptions())