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

create NetInput from base64 string #789

Open innovacion-novitech opened 3 years ago

innovacion-novitech commented 3 years ago

Hi, I'm trying do create a webservice to do face matching, so I'm writting code with textscript and express, I can get the picture in base64 but I'm trying to do a face matching but in the middle I don't know how to create a NetInput from base 64 string.

I tryied to create an Image but when I run I get this error: (node:10663) UnhandledPromiseRejectionWarning: Error: Image given has not completed loading

this is my code:

   `const imgRef = faceapi.env.getEnv().createImageElement();
     imgRef.src = 'image/jpeg;base64,'+rostros.referencia;

     imgRef.width = 393;

     imgRef.height = 574;

     console.log("imgRef complete");

     console.log(imgRef.complete);

     console.log("about detectAllFaces");

    const results = await faceapi.detectAllFaces(imgRef)
        .withFaceLandmarks().withFaceDescriptors();

`

vladmandic commented 3 years ago

it's exactly what it says 'image has not completed loading' - assigning imgRef.src is ok, but then execute actual detection inside event that triggers when image is loaded, something like imgRef.onload = () => faceapi.detectAllFaces(...)