Consistently able to stream and detect
This commit is contained in:
@ -5,7 +5,7 @@ import canvas from "canvas";
|
||||
import fs from "fs";
|
||||
import * as path from "path";
|
||||
import dotenv from "dotenv-extended";
|
||||
import { getFaceDetectorOptions, saveFile } from "../src/common";
|
||||
import { delay, getFaceDetectorOptions, saveFile } from "../src/common";
|
||||
require("@tensorflow/tfjs-node");
|
||||
|
||||
const { Canvas, Image, ImageData } = canvas;
|
||||
@ -21,7 +21,9 @@ const main = async () => {
|
||||
const modelDir = process.env.TRAINED_MODEL_DIR as string;
|
||||
|
||||
const rtsp = new Rtsp("rtsp://brandon:asdf1234@192.168.1.229/live", {
|
||||
rate: 10,
|
||||
rate: 0.5,
|
||||
image: true,
|
||||
codec: "copy",
|
||||
});
|
||||
const faceDetectionNet = nets.ssdMobilenetv1;
|
||||
|
||||
@ -38,21 +40,20 @@ const main = async () => {
|
||||
rtsp.on("data", async (data: Buffer) => {
|
||||
const input = ((await canvas.loadImage(data)) as unknown) as ImageData;
|
||||
const out = faceapi.createCanvasFromMedia(input);
|
||||
|
||||
// fs.writeFileSync(path.join(__dirname, "image.jpg"), data, "base64");
|
||||
await saveFile("image.jpg", data);
|
||||
const resultsQuery = await faceapi
|
||||
.detectAllFaces(out, getFaceDetectorOptions(faceDetectionNet))
|
||||
.withFaceLandmarks()
|
||||
.withFaceDescriptors();
|
||||
|
||||
for (const res of resultsQuery) {
|
||||
const bestMatch = matcher.findBestMatch(res.descriptor);
|
||||
console.log(bestMatch.label);
|
||||
const bestMatch = matcher.matchDescriptor(res.descriptor);
|
||||
console.log("Face Detected: " + bestMatch.label);
|
||||
}
|
||||
});
|
||||
|
||||
rtsp.on("error", (err) => {
|
||||
console.log(err);
|
||||
// console.log(err);
|
||||
});
|
||||
|
||||
rtsp.start();
|
||||
|
Reference in New Issue
Block a user