UNPKG

nexus-react-core

Version:

A comprehensive React toolkit with services, hooks, and Redux store management

49 lines 1.67 kB
"use strict"; // Face detection service for DGN Platform // Note: This requires @tensorflow/tfjs and @tensorflow-models/blazeface to be installed Object.defineProperty(exports, "__esModule", { value: true }); exports.setFaceDetectionDependencies = void 0; exports.initializeFaceDetector = initializeFaceDetector; exports.detectFace = detectFace; let model = null; let tf = null; let blazeface = null; // Function to set TensorFlow and BlazeFace dependencies const setFaceDetectionDependencies = (tensorFlow, blazeFaceModule) => { tf = tensorFlow; blazeface = blazeFaceModule; }; exports.setFaceDetectionDependencies = setFaceDetectionDependencies; async function initializeFaceDetector() { if (!tf || !blazeface) { console.error("Face detection dependencies not set. Please call setFaceDetectionDependencies() first."); return false; } if (!model) { try { await tf.setBackend("webgl"); await tf.ready(); model = await blazeface.load(); console.log("Face detector initialized successfully"); return true; } catch (error) { console.error("Error initializing face detector:", error); return false; } } return true; } async function detectFace(video) { if (!model || video.readyState !== 4) return null; try { const predictions = await model.estimateFaces(video, false); return predictions.length > 0 ? predictions[0] : null; } catch (error) { console.error("Face detection error:", error); return null; } } //# sourceMappingURL=faceDetection.js.map