npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-face-liveness-detection

v0.1.0

Published

A React component for liveness detection using MediaPipe Face Mesh.

Downloads

81

Readme

react-face-liveness-detection

A React component for liveness detection using MediaPipe Face Mesh. Built with TypeScript.

Installation

npm install react-face-liveness-detection

Usage

import React from "react";
import { LivenessDetection } from "react-face-liveness-detection";

const App = () => {
  const handleVerification = () => {
    console.log("User verified!");
    // Perform actions after successful verification (e.g., redirect, submit data)
  };

  const handleError = (err: any) => {
    console.error("Liveness detection error:", err);
    // Handle errors (e.g., display an error message)
  };

  return (
    <div>
      <LivenessDetection
        onVerified={handleVerification}
        onError={handleError}
        instructions={[
          { text: "Open your mouth wide", type: "mouth", duration: 3 },
          { text: "Blink twice", type: "blink", count: 2 },
          { text: "Smile broadly", type: "smile", duration: 2 },
        ]}
        style={{
          container: {}, // Add any custom styles here
          alert: { backgroundColor: "lightblue", color: "darkblue" },
          canvas: { border: "2px solid green" },
        }}
        thresholds={{
          // Adjust thresholds if needed
          EAR_THRESHOLD: 0.1,
          MAR_THRESHOLD: 0.15,
          SMILE_THRESHOLD: 3.0,
        }}
      />
    </div>
  );
};

export default App;

Props

| Prop | Type | Description | Default | | ----------------------- | ---------------------- | ----------------------------------------------------------------- | -------- | | instructions | Instruction[] | Array of instruction objects. See "Instruction Object Structure". | See code | | onVerified | () => void | Callback function called when the user is verified. | | | onError | (error: any) => void | Callback function called when an error occurs. | | | cameraWidth | number | Width of the camera stream. | 640 | | cameraHeight | number | Height of the camera stream. | 480 | | canvasWidth | number | Width of the canvas element. | 400 | | canvasHeight | number | Height of the canvas element. | 576 | | thresholds | Thresholds | Object containing EAR, MAR, and SMILE thresholds | See code | | randomizeInstructions | boolean | Whether to randomize the order of instructions. | true | | style | Style | Object to customize styles. See "Styling". | {} |

Instruction Object Structure

type Instruction = {
  text: string; // Text to display to the user
  type: "mouth" | "blink" | "smile"; // Type of action
  duration?: number; // Duration in seconds (for 'mouth' and 'smile')
  count?: number; // Number of times to perform action (for 'blink')
};

Styling

You can customize the styles using the style prop:

type Style = {
  container?: React.CSSProperties; // Styles for the main container
  alert?: React.CSSProperties; // Styles for the alert box
  canvas?: React.CSSProperties; // Styles for the canvas element
  loadingIndicator?: React.CSSProperties; // Styles for the loading indicator
};

Thresholds

type Thresholds = {
  EAR_THRESHOLD: number;
  MAR_THRESHOLD: number;
  SMILE_THRESHOLD: number;
};

You might need to adjust these thresholds based on lighting conditions, camera quality, and individual facial features.

Demo

The simplest way to create a demo is to create a new React project using Create React App (or similar):

npx create-react-app my-liveness-demo
cd my-liveness-demo
npm install react-face-liveness-detection

Then, replace the contents of src/App.tsx with the usage example provided above. Now you can start your demo app:

npm start