Search code examples
javascriptcomputer-visiongetusermedia

Event listener to handle headtrackr.js


I want to be able to scroll a page with head movements using headtrackr.js

https://github.com/auduno/headtrackr

I have implemented the code onto a basic html page.

<html>
<head>
<title>Test</title>
  <script src="headtrackr.js"></script>

</head>
<body>
<canvas id="inputCanvas" width="320" height="240" style="display:none"></canvas>
<video id="inputVideo" autoplay loop></video>
<script type="text/javascript">
  var videoInput = document.getElementById('inputVideo');
  var canvasInput = document.getElementById('inputCanvas');
  var htracker = new headtrackr.Tracker();
  htracker.init(videoInput, canvasInput);
  htracker.start();
</script>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. </p>
</body>
</html>

The above is SSL-enabled - the video appears. The face gets detected. But the document doesn't scroll.

Do I need something else? Like a listener to read the headtrackr readings? I cannot find this on the documentation on github or http://www.digitoffee.com/video/scroll-a-document-by-just-moving-your-head/428/


Solution

  • Maybe try adding this event listener to change whatever it is you want to do?

    document.addEventListener('headtrackingEvent', function(e) {
     window.scrollTo( e.x, e.y );
    }