auduno / headtrackr

Javascript library for headtracking via webcam and WebRTC/getUserMedia
3.69k stars 504 forks source link

Stable Head Angle Value #43

Closed romin4you closed 8 years ago

romin4you commented 8 years ago

Hello, For a very large projects, i have to implement headtracking where the elements on the right & left side of the screen will become active if the user look at them(turn their head).

I implemented your code, but i have problem with returned event.angle. The "event.angle" is not accurate. for example i can't say that: if event.angle = 1.5 (user is looking at center of screen) if event.angle > 1.6 (user is looking at the right side) if event.angle < 1.4 (user is looking at the left side)

now sometimes event.angle return 1.5 when you are looking at the center of the screen and other times 1.7 etc. so i can't tell where the user is looking.

Do you have any solution for this please?

My code:

htracker = new headtrackr.Tracker({
        altVideo: {
            ogv: "./media/capture5.ogv",
            mp4: "./media/capture5.mp4"
        },
        calcAngles: true,
        ui: false,
        headPosition: false,
        debug: debugOverlay
    });
    htracker.init(videoInput, canvasInput);
    htracker.start();

document.addEventListener("facetrackingEvent", function (event) {

    if (event.angle < 1.58) {
        document.getElementById('female').style.color = "red";
        document.getElementById('male').style.color = "#5f6a72";
        console.log('left');

    } else if (event.angle > 1.62) {
        document.getElementById('female').style.color = "#5f6a72";
        document.getElementById('male').style.color = "red";
        console.log('right');

    } else {
        console.log('center');
    }

});
auduno commented 8 years ago

Hi, the angle you get from headtrackr does not describe the "yaw" angle of the how the head is turned, but rather the "roll" angle of the head (see this image for explanation of "roll" and "yaw" angles). Headtrackr is unfortunately not really able to measure the angle you want.

I think it will be a bit challenging to find libraries that do what you want, you would probably need "eyetracking" (which AFAIK does not exist for javascript) in order for it to work properly. You can however look at clmtrackr, where it's possible to get the "yaw" angle of the head via the parameters of the model, but I suspect the output is too noisy to say something about where someone is looking.