Code Monkey home page Code Monkey logo

headpos's Introduction

This simplified library gives position (up/down/lest/right) of ๐Ÿ™‚ head/face including its magnitude/degree with the 6๏ธโƒฃ faical keypoints (x,y). This is backed by MediaPipe. The whole library and its dependencies are just in KBs. The memory footprint is very low on realtime environment and can run on very low resources. There are options to ๐ŸŽ›๏ธ control the time between inferences which reduces unnecessary computations.

๐Ÿš€ Demo

Check the live demo.

๐Ÿ“‰ Usage

Just include this JS dependency. Doesn't need JQuery.

<script src="https://cdn.jsdelivr.net/gh/SushantGautam/[email protected]/headpos.js"></script>
<script>

  // define a callback to handle the results
  OnResults = function (rs) {console.log(rs)}
  
 // initlialize HeadPos. Other optional congifs can also be added as required.
  let headpos = HeadPos.Init(OnResults);
    
</script>

๐Ÿ“Š Results

image

Callback will get a dictionary with:

{
HorizontalDirection: "Right"
HorizontalMagnitude: 0.9363492190335054
VerticalDirection: "Down"
VerticalMagnitude: 1.3243558415961285,
pose: {"..."}
}

pose contains a dict with 6 key points (x,y) of right eye, left eye, nose tip, mouth center, right ear tragion, and left ear tragion and a reference to the canvas.

๐ŸŽˆ Methods

  1. InitHeadPos Initialize the instance. This library has a singleton implementation.
let headpos = HeadPos.Init(
    HeadPosOnResults,  //callback on log value
    HeadPosDIV = document.getElementById('headpos'), // div to render headpos
    interval = 100, // time in ms to wait between callbacks, 0 is as fast as possible
	minDetectionConfidence =0.5, //Face Recognition threshold 
	 model = "short",  //  short-range model that works best for faces within 2 meters from the camera 
	 selfieMode = false,  //invert the camera 
	); 

You can define a div/p element as:

<div id='headpos'></div>

and pass the element to HeadPosDIV. The HeadPos output canvas will be prepended inside the given element. If nothing is passed, the canvas will be appended to the root of HTML.

  1. updateInterval Dynamically udate time in ms to wait between callbacks.
headpos.updateInterval(1000) 
  1. pause Pause the inference. Canvas rendering will also pause.
headpos.pause() 
  1. resume Resume the inference after pause. Canvas rendering will also resume.
headpos.resume() 

๐Ÿ™‹ Improving

PRs, issues, ideas or suggestions are highly welcome. ๐Ÿ‘Œ

๐Ÿญ Built With

headpos's People

Contributors

sushantgautam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

boo-code

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.