<commit_before>console.log(`It's working !`)

/* ------------------------------------------------------------------- */


// We define our video input as the <video> tag (id = webcam)
var webcam = document.getElementById('webcam');
// var box = [boxX, boxY, boxWidth, boxHeight];



/* ------------------------------------------------------------------- */


// Access to webcam stuff
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia 
|| navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
 
if (navigator.getUserMedia) {       
    navigator.getUserMedia({video: true}, handleVideo, videoError);
}
 
// Create the actual webcam stream into our webcam HTML object 
function handleVideo(stream) {
    webcam.src = window.URL.createObjectURL(stream);
}
 
function videoError(e) {
    console.log("Camera stream is not working, please allow access or try on a recent browser.");
}


// Define a new tracker object
var ctracker = new clm.tracker({useWebGL : true});
// We initialize the object with a face model and start to track the webcam stream
ctracker.init(pModel);
ctracker.start(webcam);


/* ------------------------------------------------------------------- */


// Draw the face
var canvasInput = document.getElementById('drawCanvas');
var cc = canvasInput.getContext('2d');

function drawLoop() {
    requestAnimationFrame(drawLoop);
    cc.clearRect(0, 0, canvasInput.width, canvasInput.height);
    ctracker.draw(canvasInput);
  }

   drawLoop();


// function animate(box) {
// 	ctracker.start(document.getElementById('image'), box);
// 	drawLoop();
// }

// 	animate();
   

/* ------------------------------------------------------------------- */

// Get current face data positions at every frame
function positionLoop() {
	requestAnimationFrame(positionLoop);
	var positions = ctracker.getCurrentPosition();
// Put "positions" in an if statement (otherwise positions return null) 
      if (positions) {

    //     for (var p = 15; p <= 18; p++) {
    //     console.log("positions x = " + positions[p][0] + "\nposition y = " + positions[p][1]); 
    // }

      var eyebrowLeftHeight = positions[19][1] + positions[20][1] + positions[21][1] + positions[22][1];
      var eyebrowLeftOK = eyebrowLeftHeight / 4;
      var eyebrowRightHeight = positions[18][1] + positions[17][1] + positions[16][1] + positions[15][1];
      var eyebrowRightOK = eyebrowRightHeight / 4;
      var averageEyebro = (eyebrowLeftOK + eyebrowRightOK) / 2      
      var nose = positions[33][1];
  

	// Callback if the tracking fit your face or not
	  var ok = "Your face is successfuly tracked !";
	  var notok = "Tracking not working...";
	  var score = ctracker.getScore();
	  if(score > 0.50) {
		document.getElementById('tracked').innerHTML = ok;
	  } else {
		document.getElementById('tracked').innerHTML = notok;
	  }

	// Draw the face bounding box  
	  var myBox = getAABB(positions);
	  cc.strokeStyle="#FF0000";
	  cc.strokeRect(myBox.x, myBox.y, myBox.width, myBox.height);
	// Print the values
	// diff is the distance between eyebrows and nose in relation to the bounding box
	  var diff = Math.abs((nose - averageEyebro) / myBox.height) * 100;
      console.log("averageEyebro: " + averageEyebro + "\nnose: " + nose + "\ndiff: " + diff);
	 	
	 	if(diff > 13) {
	 		cc.strokeStyle="#0023FF";
	 		cc.lineWidth=5;
	 		cc.strokeRect(myBox.x, myBox.y, myBox.width, myBox.height);
	}   else {
	 		cc.lineWidth=1;
	 }
  }
}

  positionLoop();


/* ------------------------------------------------------------------- */



// Function to get the axis aligned bounding box (AABB)

function getAABB(points) {
  if (points && points.length > 0) {
    let min = {x: Number.POSITIVE_INFINITY, y: Number.POSITIVE_INFINITY };
    let max = {x: Number.NEGATIVE_INFINITY, y: Number.NEGATIVE_INFINITY };
    for (let i = 0; i < points.length; i++) {
      let point = points[i];
      let x = point[0];
      let y = point[1];
      if (x < min.x) min.x = x;
      else if (x > max.x) max.x = x;

      if (y < min.y) min.y = y;<commit_msg>better indenting, clean some parts<commit_after>console.log(`It's working !`)

/* ------------------------------------------------------------------- */


// We define our video input as the <video> tag (id = webcam)
var webcam = document.getElementById('webcam');


/* ------------------------------------------------------------------- */


// Access to webcam stuff
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia 
|| navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
 
if (navigator.getUserMedia) {       
    navigator.getUserMedia({video: true}, handleVideo, videoError);
}
 
// Create the actual webcam stream into our webcam HTML object 
function handleVideo(stream) {
    webcam.src = window.URL.createObjectURL(stream);
}
 
function videoError(e) {
    console.log("Camera stream is not working, please allow access or try on a recent browser.");
}


// Define a new tracker object
var ctracker = new clm.tracker({useWebGL : true});
// We initialize the object with a face model and start to track the webcam stream
ctracker.init(pModel);
ctracker.start(webcam);


/* ------------------------------------------------------------------- */


// Draw the face
var canvasInput = document.getElementById('drawCanvas');
var cc = canvasInput.getContext('2d');

function drawLoop() {
    requestAnimationFrame(drawLoop);
    cc.clearRect(0, 0, canvasInput.width, canvasInput.height);
    ctracker.draw(canvasInput);
  }

drawLoop();
   

/* ------------------------------------------------------------------- */

// Get current face data positions at every frame
function positionLoop() {
	requestAnimationFrame(positionLoop);
	var positions = ctracker.getCurrentPosition();
// Put "positions" in an if statement (otherwise positions return null) 
    if (positions) {

      var eyebrowLeftHeight = positions[19][1] + positions[20][1] + positions[21][1] + positions[22][1];
      var eyebrowLeftOK = eyebrowLeftHeight / 4;
      var eyebrowRightHeight = positions[18][1] + positions[17][1] + positions[16][1] + positions[15][1];
      var eyebrowRightOK = eyebrowRightHeight / 4;
      var averageEyebro = (eyebrowLeftOK + eyebrowRightOK) / 2      
      var nose = positions[33][1];
  

	// Callback if the tracking fit your face or not
	  var ok = "Your face is successfuly tracked !";
	  var notok = "Tracking not working...";
	  var score = ctracker.getScore();
	  if(score > 0.50) {
		document.getElementById('tracked').innerHTML = ok;
	  } else {
		document.getElementById('tracked').innerHTML = notok;
	  }

	// Draw the face bounding box  
	  var myBox = getAABB(positions);
	  cc.strokeStyle="#FF0000";
	  cc.strokeRect(myBox.x, myBox.y, myBox.width, myBox.height);
	// Print the values
	// diff is the distance between eyebrows and nose in relation to the bounding box
	  var diff = Math.abs((nose - averageEyebro) / myBox.height) * 100;
      console.log("averageEyebro: " + averageEyebro + "\nnose: " + nose + "\ndiff: " + diff);
	 	
	if(diff > 13) {
	  cc.strokeStyle="#0023FF";
	  cc.lineWidth=5;
	  cc.strokeRect(myBox.x, myBox.y, myBox.width, myBox.height);
	} else {
	 	cc.lineWidth=1;
	}
  }
}

  positionLoop();


/* ------------------------------------------------------------------- */



// Function to get the axis aligned bounding box (AABB)

function getAABB(points) {
  if (points && points.length > 0) {
    let min = {x: Number.POSITIVE_INFINITY, y: Number.POSITIVE_INFINITY };
    let max = {x: Number.NEGATIVE_INFINITY, y: Number.NEGATIVE_INFINITY };
    for (let i = 0; i < points.length; i++) {
      let point = points[i];
      let x = point[0];
      let y = point[1];
      if (x < min.x) min.x = x;
      else if (x > max.x) max.x = x;

      if (y < min.y) min.y = y;
{'fraction_non_alphanumeric': 0.21014492753623187, 'fraction_numerical': 0.01474701245868294, 'mean_word_length': 2.373499142367067, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1393457', 'n_tokens_mistral': 2528, 'n_tokens_neox': 2336, 'n_words': 636}