score:2

Accepted answer

you need to change the order of function declaration. you can not call const variables before they were declared.

//passing image from my react component
const facedetector = (image) => {
  const imageref = image;


  // this function should detect the face from imageref and should console the size of detector
  const handleimage = async () => {
    const detections = await faceapi
        .detectsingleface(imageref, new faceapi.tinyfacedetectoroptions())
    console.log(`width ${detections.box._width} and height ${detections.box._height}`);
}

   const loadmodels = async () => {
   // models are present in public and they are getting loaded
    const model_url = process.env.public_url + "/models";
    promise.all([
        faceapi.nets.tinyfacedetector.loadfromuri(model_url),
        faceapi.nets.facelandmark68net.loadfromuri(model_url),
        faceapi.nets.facerecognitionnet.loadfromuri(model_url),
        faceapi.nets.faceexpressionnet.loadfromuri(model_url)
    ])
         // this is rising the issue. i want to call this function after my models loaded so it can detect face
        .then(handleimage)
        .catch((e) => console.error(e));
   };
   loadmodels();


}

Related Query

More Query from same tag