UNPKG

react-native-vision-camera-face-detector

Version:

Frame Processor Plugin to detect faces using MLKit Vision Face Detector for React Native Vision Camera!

54 lines (52 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; exports.useFaceDetectorOutput = useFaceDetectorOutput; var _react = require("react"); var _factory = require("../factory"); // types /** * Use a {@linkcode FaceDetector}. * * A {@linkcode FaceDetector} can be used to detect * {@linkcode Face}s in a {@linkcode Frame} in a Frame * Processor. * * @example * ```ts * const FaceDetector = useFaceDetector({...}) * const frameOutput = useFrameOutput({ * onFrame(frame) { * 'worklet' * const faces = FaceDetector.detectFaces(frame) * console.log(`Detected ${faces.length} faces!`) * frame.dispose() * } * }) * ``` */ function useFaceDetectorOutput({ onFacesDetected, onError, outputResolution = 'preview', ...options }) { const stableOnFacesDetected = (0, _react.useRef)(onFacesDetected); stableOnFacesDetected.current = onFacesDetected; const stableOnError = (0, _react.useRef)(onError); stableOnError.current = onError; return (0, _react.useMemo)(() => (0, _factory.createFaceDetectorOutput)({ onFacesDetected(faces) { stableOnFacesDetected.current(faces); }, onError(error) { stableOnError.current(error); }, outputResolution: outputResolution, ...options }), [options]); } var _default = exports.default = useFaceDetectorOutput; //# sourceMappingURL=useFaceDetectorOutput.js.map