vladmandic / face-api

FaceAPI: AI-powered Face Detection & Rotation Tracking, Face Description & Recognition, Age & Gender & Emotion Prediction for Browser and NodeJS using TensorFlow/JS
https://vladmandic.github.io/face-api/demo/webcam.html
MIT License
824 stars 149 forks source link

Question: #144

Closed orangecoding closed 1 year ago

orangecoding commented 1 year ago

Hi,

Thanks for this awesome lib!

I'm using it to extract faces from photos, check if they are tilted, if they are, rotate the canvas to straighten the face and then store it as a new image.

I'm basically doing it like this:

    const c = await image(inputPath);
    const face = await detectFace(c);
    const locations = await faceapi.locateFaces(c);
    const faceImg = await faceapi.extractFaces(c, locations);
    const final = canvas.createCanvas(face.landmarks.imageWidth, face.landmarks.imageHeight);

    const roll = face.angle.roll;
    final.getContext('2d').rotate(roll * Math.PI / 180);
    final.getContext('2d').drawImage(faceImg[0], 0, 0);
    writeFileToDirectory(outputPath, final.toBuffer('image/jpeg'));

I'm having 2 questions.

My endgoal is to have all faces the same size (e.g 800x600) later on

vladmandic commented 1 year ago

locateFaces is a reduced version of detectAllFaces, so in your cases just use locateFaces, you shouldn't need anything before
for resizing, there are tons of options, but since you already have a canvas you've created, you can simply resize it fore writing it to file

vladmandic commented 1 year ago

closing due to inactivity, but can be reopened if additional information is needed

orangecoding commented 1 year ago

Thanks :)