【发布时间】:2018-10-03 16:58:52
【问题描述】:
我正在尝试构建一个面部识别模块,以便在我的项目中使用它。该模块稍后将在 electron.js 中用于构建跨平台应用程序。
基本思路是:
向用户展示了一个网页,该网页显示了他/她的网络摄像头供稿。她/他可以单击捕获按钮,将图像保存在服务器端。这将重复多次以获得训练数据来训练面部识别模型。我使用名为“node-webcam”的第三方 npm 模块实现了图像捕获部分:
const nodeWebCam = require('node-webcam');
const fs = require('fs');
const app = require('express')();
const path = require('path');
// specifying parameters for the pictures to be taken
var options = {
width: 1280,
height: 720,
quality: 100,
delay: 1,
saveShots: true,
output: "jpeg",
device: false,
callbackReturn: "location"
};
// create instance using the above options
var webcam = nodeWebCam.create(options);
// capture function that snaps <amount> images and saves them with the given name in a folder of the same name
var captureShot = (amount, i, name) => {
var path = `./images/${name}`;
// create folder if and only if it does not exist
if(!fs.existsSync(path)) {
fs.mkdirSync(path);
}
// capture the image
webcam.capture(`./images/${name}/${name}${i}.${options.output}`, (err, data) => {
if(!err) {
console.log('Image created')
}
console.log(err);
i++;
if(i <= amount) {
captureShot(amount, i, name);
}
});
};
// call the capture function
captureShot(30, 1, 'robin');
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.listen(3000, () => {
console.log("Listening at port 3000....");
});
但是,在这部分之后我迷路了。我不知道如何让实时提要显示在用户看到的网页上。另外,我后来意识到这是一个服务器端代码,没有办法从客户端调用 captureShot() 函数。任何帮助将不胜感激。
【问题讨论】:
标签: javascript node.js