Giter Club home page Giter Club logo

gaze-detection's Introduction

Gaze-detection

Use machine learning in JavaScript to detect eye movements and build gaze-controlled experiences!

Demo

Visit https://gaze-keyboard.netlify.app/ (Works well on mobile too!!) πŸ˜ƒ

Inspired by the Android application "Look to speak".

Uses Tensorflow.js's face landmark detection model.

Detection

This tool detects when the user looks right, left, up and straight forward.

How to use

Install

As a module:

npm install gaze-detection --save

Code sample

Start by importing it:

import gaze from "gaze-detection";

Load the machine learning model:

await gaze.loadModel();

Then, set up the camera feed needed for the detection. The setUpCamera method needs a video HTML element and, optionally, a camera device ID if you are using more than the default webcam.

const videoElement = document.querySelector("video");

const init = async () => {
  // Using the default webcam
  await gaze.setUpCamera(videoElement);

  // Or, using more camera input devices
  const mediaDevices = await navigator.mediaDevices.enumerateDevices();
  const camera = mediaDevices.find(
    (device) =>
      device.kind === "videoinput" &&
      device.label.includes(/* The label from the list of available devices*/)
  );

  await gaze.setUpCamera(videoElement, camera.deviceId);
};

Run the predictions:

const predict = async () => {
  const gazePrediction = await gaze.getGazePrediction();
  console.log("Gaze direction: ", gazePrediction); //will return 'RIGHT', 'LEFT', 'STRAIGHT' or 'TOP'
  if (gazePrediction === "RIGHT") {
    // do something when the user looks to the right
  }
  let raf = requestAnimationFrame(predict);
};
predict();

Stop the detection:

cancelAnimationFrame(raf);

gaze-detection's People

Contributors

charliegerard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gaze-detection's Issues

Not able to import the module

I am not able to import the module, it is failing the following error

Attempted import error: 'gaze-detection' does not contain a default export (imported as 'gaze').
ERROR in ./src/App.js 17:16-32
export 'default' (imported as 'gaze') was not found in 'gaze-detection' (module has no exports)

ERROR in ./src/App.js 22:6-13
export 'default' (imported as 'gaze') was not found in 'gaze-detection' (module has no exports)

ERROR in ./src/App.js 30:17-26
export 'default' (imported as 'gaze') was not found in 'gaze-detection' (module has no exports)

webpack compiled with 3 errors

this is the code i tried:

import gaze from "gaze-detection";

How to use it on Android

I have termux in my phone,
So how i can use it with my phone ??
And BTW it's awesome project ☺️

Doubt

Hello, interesting application.
I had heard about Tensor-Flow but not much else.
I ask you, this project is free software? or is it a library that you have implemented that uses tensor-flow? can you explain?

Thanks

How can I prevent the video from resizing?

Hi, I used this module in my react project with webcam.
I want to set the webcam size to 640480, but this module changes the webcam size to 500500.
Is there any way to prevent this?
Thank you for the awesome project. πŸ€—

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.