justadudewhohacks / face-api.js

JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js
MIT License
16.68k stars 3.71k forks source link

faceapi.BoxWithText is not a constructor #643

Open Bioswami-nfac opened 4 years ago

Bioswami-nfac commented 4 years ago

Hi,

I am getting this error when I am trying to create a new Box with custom text.

I am using the usual code for creating the box with text:

const boxesWithText = results.map((bestMatch, i) => {
  const box = fullFaceDescriptions[i].detection.box
  const text = bestMatch.toString()
  const boxWithText = new faceapi.BoxWithText(box, text)
return(boxWithText)
})

I get the following error:

renderer.js:215 Uncaught (in promise) TypeError: faceapi.BoxWithText is not a constructor

Can you point me to any reason for this?

Regards, Arun

Bioswami-nfac commented 4 years ago

In case anyone else is facing the issue, here is what I did. I used the lower level functions to draw the box and the expressions.

for (var i = 0; i < resizedDetections.length; i++){
        var thisRect = resizedDetections[i].detection.box;
        //faceRects.push(resizedDetections[i].detection);
        var thisBox = {bottom: thisRect.bottom, left: thisRect.left, top: thisRect.top, right: thisRect.right};
        var thisFaceExpressions = resizedDetections[i].expressions;
        const maxValue = Math.max(...Object.values(thisFaceExpressions));
        const emotion = Object.keys(thisFaceExpressions).filter(
          item => thisFaceExpressions[item] === maxValue
        );
        emotionText = emotion.toString();
          if(emotionIndex == 0  || emotionIndex == 1){
            color = RED;
          }else if (emotionIndex == 2 || emotionIndex == 4 ){
            color = ORANGE;
          }else if (emotionIndex == 3){
            color = DARK_GREEN;
          }else if(emotionIndex == 5){
            color = LIGHT_GREEN;
          }else{
            color = YELLOW;
          }
          var thisBoxOptions = ({boxColor: color, label: emotionText});
          var thisDrawBox = new faceapi.draw.DrawBox(thisBox,thisBoxOptions)
           thisDrawBox.draw(canvas);
}
YklymGz commented 1 year ago

I think you used outdated documentation, most recent one for me was here https://github.com/justadudewhohacks/face-api.js/blob/master/README.md