eduardolundgren / tracking.js

A modern approach for Computer Vision on the web
http://trackingjs.com
Other
9.43k stars 1.44k forks source link

Eye detection #286

Open peterlunglum opened 6 years ago

peterlunglum commented 6 years ago

I'm playing around with the object detection and it detects eyes fairly decently. For a project I'm working on, I need to be able to detect if a users eyes are closed. I figured that the eye script would detect only open eyes, but apparently I tried it with a specific image and it still registers closed eyes. Is there a way to detect specifically if an eye is closed or to reduce the sensitivity of the detection script?Moreover, I'm fine with getting users to cover their eyes or some other method, just curious what the outlook is for the eye script.

murat-aka commented 6 years ago

Hi, are you trying to find out if the car driver is going to sleep.

I am not sure if this library would still detect the face if no eyes are detected.

I did find out it detects single eye. And mouth. And nose probably.

If you can get mouth and nose with the face detected. (Those all would be separate squares/rectangles) but eyes not returned. That can assume eyes closed.

If however, in your example if the eyes goto sleep after sometime, that's even easier. The mouth or nose would be same size rectangles respectively. But the rectangles for the eyes would go smaller indicating a closed eye lid. I am assuming the library takes into account the eye lids though, when finding eyes

peterlunglum commented 6 years ago

Hey @murat-aka ,

I'm using the library for a site that plays callbacks only when a user's eyes are closed. I've looked at other libraries like brfv4, which has very sensitive blink detection , but I can't explicitly get that to detect and maintain a that a user's eyes are closed.

I was playing with the face_hello_world example in the build using different photos, and it still detects eyes in a tracking object even if the eyes are closed. I had to use a photo where eyes were covered by a eye-mask before it stopped recognizing eyes. This is fine for my current use case as far as I can tell, but just wondering if there was a way to fine tune or adjust the eye library to detect eyes closed without the need for a cover.

murat-aka commented 6 years ago

Hi, the mask color would make a big difference I think. I ll check the library to see how the eye detection exactly work. And then let you know.

That brfv4 library have more options that you can play with. It's based on opencv library

murat-aka commented 6 years ago

Hi more update,

The library uses haar cascades for detection. https://github.com/eduardolundgren/tracking.js/tree/master/src/detection/training/haar

You can train new cascades with MATLAB. People find it easy to do. I ve never done it myself.

You would need sets of faces with the mask and then without the masks for training. https://docs.opencv.org/3.3.0/d7/d8b/tutorial_py_face_detection.html

The only options you can play with in this library are


/**
   * Detects through the HAAR cascade data rectangles matches.
   * @param {pixels} pixels The pixels in a linear [r,g,b,a,...] array.
   * @param {number} width The image width.
   * @param {number} height The image height.
   * @param {number} initialScale The initial scale to start the block
   *     scaling.
   * @param {number} scaleFactor The scale factor to scale the feature block.
   * @param {number} stepSize The block step size.
   * @param {number} edgesDensity Percentage density edges inside the
   *     classifier block. Value from [0.0, 1.0], defaults to 0.2. If specified
   *     edge detection will be applied to the image to prune dead areas of the
   *     image, this can improve significantly performance.
   * @param {number} data The HAAR cascade data.
   * @return {array} Found rectangles.
   * @static
   */
  tracking.ViolaJones.detect = function(pixels, width, height, initialScale, scaleFactor, stepSize, edgesDensity, data) {

https://github.com/eduardolundgren/tracking.js/blob/master/src/detection/ViolaJones.js

peterlunglum commented 6 years ago

So I have played around with settings and have functionally gotten the ability to track eyes to a certain degree. Is there a way to better retain eye detection and remove false positives? Or maybe a better way to phrase it, is there a way to call the tracker at a different frame rate or amount of times per second?

tetreault commented 6 years ago

Am having this issue as well. I can take a photo of my face using my iphone X in great lighting looking directly at the camera w/o blinking and i'm getting maybe a 40% success rate on eye tracking @murat-aka @peterlunglum

tetreault commented 6 years ago

@peterlunglum have you progressed any further with the accuracy improvement?

murat-aka commented 6 years ago

Does that Apple not come with a night camera. After all that money you put in.

Autopilot enabled on Tesla’s cars in October 2015. The first person known to die using Model S crashed into a truck that turned across his path in Florida, in May 2016. Neither he nor the car’s computers saw the white truck against the bright sky.

Tesla modified Autopilot to rely more on data from its radar, and less on the camera, to spot obstacles in the car’s path.