homebridge-face-location/src/common.ts

33 lines
879 B
TypeScript
Raw Normal View History

import * as faceapi from "@vladmandic/face-api";
import * as path from "path";
import fs from "fs";
// SsdMobilenetv1Options
export const minConfidence = 0.5;
// TinyFaceDetectorOptions
export const inputSize = 408;
export const scoreThreshold = 0.5;
export const getFaceDetectorOptions = (net: faceapi.NeuralNetwork<any>) => {
return net === faceapi.nets.ssdMobilenetv1
? new faceapi.SsdMobilenetv1Options({ minConfidence })
: new faceapi.TinyFaceDetectorOptions({ inputSize, scoreThreshold });
};
2020-12-10 17:51:35 +00:00
export function saveFile(basePath: string, fileName: string, buf: Buffer) {
if (!fs.existsSync(basePath)) {
fs.mkdirSync(basePath);
}
2020-12-10 17:51:35 +00:00
fs.writeFileSync(path.resolve(basePath, fileName), buf, "base64");
}
2020-11-27 17:31:53 +00:00
export const delay = (ms: number): Promise<void> => {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, ms);
});
};