Git Product home page Git Product logo

react-hooks-collection's Introduction

react-hooks-collection

Personal collection of react hooks

usePrinting

Provide binding to trigger event before/after print. For example, we can use it to refit our graph network to the new layout.

Usage

import React, { useState, useEffect } from 'react';
import { usePrinting } from 'hooks/usePrinting';
import Graph from 'react-graph-vis';
import { graph, options, events } from "./graph";

const Index = ({ height, width, className }) => {
  const [network, setNetwork] = useState(null);
  const printing = usePrinting()
  useEffect(() => { if (network) network.fit() }, [printing]);
  return <Graph
      graph={graph}
      options={options}
      events={events}
      getNetwork={network => setNetwork(network)}
    />
};

faceapi.js hooks

Provide bindings with faceapi.js repository.

useFaceApiDetection

React state hook that load model and provide detections according to an input source (video, image, ...anything faceapi.js accept).

Usage

import { useRef } from 'react';
import { useFaceApiDetection } from './react-hooks-collection/face-api.js';
import * as faceapi from 'face-api.js';

const modelPath = "/assets/faceapi/models";
const Demo = () => {
  const videoRef = useRef();
  const [model, setModel] = useState(faceapi.SsdMobilenetv1);
  const [detections, setFaceApiInput] = useFaceApiDetection(videoRef, model, modelPath);
  return (
    <div>
      <video width={"640"} height={"360"} ref={videoRef} controls autoplay>
        <source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4"  />
        <source src="http://clips.vorwaerts-gmbh.de/VfE.webm"      type="video/webm" />
        <source src="http://clips.vorwaerts-gmbh.de/VfE.ogv"       type="video/ogg"  />
      </video>
      <div>X: {detections ? detections.box.x : 0}</div>
      <div>Y: {detections ? detections.box.y : 0}</div>
    </div>
  );
};

useFaceApiOverlay

React state hook drawing bounding boxes on a provided canvas and using faceapi.js detections.

Usage

import { useRef } from 'react';
import { useFaceApiDetection, useFaceApiOverlay } from './react-hooks-collection/face-api.js';
import * as faceapi from 'face-api.js';

const modelPath = "/assets/faceapi/models";
const Demo = () => {
  const videoRef = useRef();
  const [model, setModel] = useState(faceapi.SsdMobilenetv1);
  const [detections, setFaceApiInput] = useFaceApiDetection(videoRef, model, modelPath);
  const canvasRef = useRef()
  useFaceApiOverlay(detections, canvasRef);
  return (
    <div>
      <video width={"640"} height={"360"} ref={videoRef} controls autoplay>
        <source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4"  />
        <source src="http://clips.vorwaerts-gmbh.de/VfE.webm"      type="video/webm" />
        <source src="http://clips.vorwaerts-gmbh.de/VfE.ogv"       type="video/ogg"  />
      </video>
      <div>X: {detections ? detections.box.x : 0}</div>
      <div>Y: {detections ? detections.box.y : 0}</div>
      <canvas width={"640"} height={"360"} ref={canvasRef} />
    </div>
  );
};

react-hooks-collection's People

Contributors

nestarz avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.