【发布时间】:2019-05-10 03:41:02
【问题描述】:
我尝试使用 face-api.js 从磁盘加载图像:
faceapi.fetchImage(path.resolve(INPUT_DIR, 'input1.jpg');
它会抛出以下错误:Error: fetch - missing fetch implementation for nodejs environment
还有其他方法可以从磁盘加载图像并使用 nodejs 显示吗?
【问题讨论】:
我尝试使用 face-api.js 从磁盘加载图像:
faceapi.fetchImage(path.resolve(INPUT_DIR, 'input1.jpg');
它会抛出以下错误:Error: fetch - missing fetch implementation for nodejs environment
还有其他方法可以从磁盘加载图像并使用 nodejs 显示吗?
【问题讨论】:
它失败的原因是你需要实现 fetch 函数才能让它工作。当您尝试从在线检索图像时,应使用FetchImage。如果您使用的是本地磁盘中的映像,请执行以下操作:
从本地磁盘加载模块。
await faceapi.nets.ssdMobilenetv1.loadFromDisk(path.join(__dirname, 'models'));
//对我来说,我已经把所有的模块都放在了src/models/
加载画布
传递画布和模块选项(如果有)
let detectionresult = awaitfaceapi.detectAllFaces(canvas, this.getSSNMobileOptions())
【讨论】:
documentation 建议您使用canvas 执行以下操作:
const canvas = require('canvas');
faceapi.env.monkeyPatch({ Canvas, Image })
const img = await canvas.loadImage('./img.jpg');
const detections = await faceapi.detectSingleFace(img);
fetchImagewill not work with local files:
faceapi.fetchImage顾名思义在后台使用 fetch,因此它不适用于本地文件的文件路径。
【讨论】: