Closed fakob closed 4 years ago
exact same faceDescriptor value
This is indeed very suspicious, can you post an example image where this issue occurs?
The only two reasons I can think of is, that somethings wrong with your code, or theres something going wrong in the tfjs backend due to your system environment.
Could you give some information about your environment? (browser or nodejs, which browser / nodejs version, your OS and which backend you are using, cpu or webgl)
Thanks for looking into this.
Latest findings The issue with the same faceDescriptors only occurs with larger image files and only after a certain number of images. With my MoviePrint app I am using e.g. 20 images of a movie and feed it into face-api.js. When I feed in low resolution images (320x240), everything works as expected. When I do this with the same full image size (1920x1080), after the 3rd detected face it keeps throwing out the same faceDescriptor.
Does that help?
Setup and 2 example images: OS: macOS 10.14.6 Mojave Node version: v13.7.0 Electron: 4.2.10 Chromium: 69.0.3497.128 face-api.js: 0.22.0
You are probably right that it has something to do with my setup. I will investigate further.
Somehow I believe that the problem is with the image input as my boxes are already way off. I had not noticed that before.
My app is using opencv4nodejs to get the image data. I have tried 3 ways of getting my input into faceapi.detectAllFaces(input)
.
The first approach via an actual canvas brought the result seen in the image above:
faceapi.env.monkeyPatch({
Canvas: HTMLCanvasElement,
Image: HTMLImageElement,
ImageData,
Video: HTMLVideoElement,
createCanvasElement: () => document.createElement('canvas'),
createImageElement: () => document.createElement('img')
});
const mat = vid.read();
const input = document.getElementById('myCanvas');
input.height = mat.rows;
input.width = mat.cols;
const imgData = new ImageData(
new Uint8ClampedArray(matRescaled.getData()),
matRescaled.cols,
matRescaled.rows
);
const ctx = input.getContext('2d');
ctx.putImageData(imgData, 0, 0);
const detections = await faceapi.detectAllFaces(input);
Then I tried the other suggested method using node-canvas, but I don't know how to get from the opencv Mat to the image format needed. They both end in an error. I tried this.
const { Canvas, Image, ImageData } = canvas;
faceapi.env.monkeyPatch({ Canvas, Image, ImageData });
const mat = vid.read();
const input = new ImageData(
new Uint8ClampedArray(mat.getData()),
mat.cols,
mat.rows
);
const detections = await faceapi.detectAllFaces(input);
and that approach
const { Canvas, Image, ImageData } = canvas;
faceapi.env.monkeyPatch({ Canvas, Image });
const mat = vid.read();
const input = new Image();
input.width = matRescaled.cols;
input.height = matRescaled.rows;
input.src = matRescaled.getData();
const detections = await faceapi.detectAllFaces(input);
What am I doing wrong to get from opencv Mat to the needed input format?
Forgot to post the error I am getting on the last approach and noticed that there is already an issue on that - https://github.com/justadudewhohacks/face-api.js/issues/194
Finally I made it work and it seems that reading the images properly also has solved the originally stated issue. I was unfortunately not successful with node-canvas
, but made it work with tfjs-node
. Thanks to @whyboris for the tip!
import * as tf from '@tensorflow/tfjs-node';
const input = tf.node.decodeJpeg(jpgImage);
Hi I am running
faceapi.detectSingleFace(image).withFaceLandmarks().withAgeAndGender().withFaceDescriptor();
of different images/faces and most not all of them have the exact same faceDescriptor values. This seems wrong. Looking at their detection object, they clearly are different. What am I doing wrong?Here is my code where I try to find unique faces.