0.1.2 • Published 1 year ago

react-native-vision-camera-detect-faces-plugin v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-native-vision-camera-detect-faces-plugin

detect face plugin for react-native-vision-camera

Prequisites

Install react-native-vision-camera and react-native-worklets-core

npm install react-native-vision-camera react-native-worklets-core

or using yarn

yarn add react-native-vision-camera react-native-worklets-core

Please refer to this Documentation and follow the installation instructions.

Installation

npm install react-native-vision-camera-detect-faces-plugin

or using yarn

yarn add react-native-vision-camera-detect-faces-plugin

Usage

import React, { useEffect, useRef } from 'react';
import {
  Camera,
  useCameraDevice,
  useCameraPermission,
  useFrameProcessor
} from 'react-native-vision-camera';
import { detectFaces } from 'react-native-vision-camera-detect-faces-plugin';

// ...

const cameraRef = useRef<Camera>(null);

const { hasPermission, requestPermission } = useCameraPermission();
const cameraDevice = useCameraDevice('front');

const frameProcessor = useFrameProcessor((frame) => {
  'worklet';
  const faces = detectFaces(frame);

  if (faces.length > 0) {
    console.log(`faces in frame: ${faces[0].smilingProbability}`);
  }
}, []);

useEffect(() => {
  if (hasPermission) return;
  requestPermission();
}, []);

return (
  <Camera
    ref={cameraRef}
    style={StyleSheet.absoluteFill}
    isActive={true}
    device={cameraDevice}
    photo={true}
    frameProcessor={frameProcessor}
  />
);

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library