Closed toguvr closed 2 years ago
package canvas
is only really needed if you want to draw outputs on it in nodejs
, otherwise there is a much simpler way
for example:
await faceapi.nets.ssdMobilenetv1.loadFromDisk('model');
await faceapi.nets.faceLandmark68Net.loadFromDisk('model');
await faceapi.nets.faceRecognitionNet.loadFromDisk('model');
await faceapi.nets.faceExpressionNet.loadFromDisk('model');
const optionsSSDMobileNet = new faceapi.SsdMobilenetv1Options({ minConfidence: 0.1, maxResults: 10 });
const buffer = fs.readFileSync('demo/sample1.jpg'); // read jpg image as binary data
const decodeT = faceapi.tf.node.decodeImage(buffer, 3); // decode jpg buffer into rgb tensor
const expandT = faceapi.tf.expandDims(decodeT, 0); // add batch dimension to rbg tensor
const result = await faceapi.detectAllFaces(expandT, optionsSSDMobileNet)
.withFaceLandmarks()
.withFaceExpressions()
.withFaceDescriptors();
faceapi.tf.dispose([decodeT, expandT]); // dispose tensors
console.log({ result });
Nice! But we can't use readfileasync for url images like images in s3 buckets
it works just the same with fetch
or any method that returns a full buffer (and there are methods like that for s3 buckets as well). for example:
const res = await fetch(imageUrl);
if (res && res.ok) buffer = await res.buffer();
when i do this, return this to me: Cannot read properties of undefined (reading 'length')
copy & paste a full stack trace, not just last line. and where does this error occur exactly?
I fixed!thanks for your help, the problem was fim1 is an array and nos an object, sorry my mistake, thanks for the help.
you're welcome!
Issue Description Canvas is with problems to deploy and do u know what is the best way to do a similarity api without canvas ? i want compare an image (that i uploaded with multer, and an image from an url). thats my code:
`const faceDetectionNet = faceapi.nets.ssdMobilenetv1; const minConfidence = 0.5;
//here i need change. const referenceImage = await canvas.loadImage(originalPath); const queryImage = await canvas.loadImage(avatar_url);