How to resize the aligned face images to a constant fixed size?
See original GitHub issueHi I am trying to display the list of detected and aligned face images in a scroll div in html5. I am able to detect and append into the div dynamically however the size of the resultant face images are all different. At which function do I change the width and height so let’s say they will all be 160x160.
const input = await faceapi.toNetInput(videoEl)
const locations = await faceapi.locateFaces(input, minConfidence)
//const resized_locations = locations.map(det => det.forSize(160, 160))
const faceImages = await faceapi.extractFaces(input.inputs[0], locations)
// detect landmarks and get the aligned face image bounding boxes
const alignedFaceBoxes = await Promise.all(faceImages.map(
async (faceCanvas, i) => {
const faceLandmarks = await faceapi.detectLandmarks(faceCanvas)
return faceLandmarks.align(locations[i])
}
))
const alignedFaceImages = await faceapi.extractFaces(input.inputs[0], alignedFaceBoxes)
// free memory for input tensors
input.dispose()
//$('#facesContainer').empty()
faceImages.forEach(async (faceCanvas, i) => {
$('#facesContainer').append(alignedFaceImages[i])
percentage = percentage + 5;
})
These are the script i used for detect and append. I tried resizing the faceCanvas, or looping through #faceContainer and resize them, or mapping the alignedFaceImages to 160x160 size but all to no avail. Any assistance is much appreciated. Thank you!
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Resize, Fit and Align Images with Filestack and React
resize =align:center, top, bottom, left, right, or faces : using align, you can choose the area of the image to focus on.
Read more >How can I make all images of different height and width the ...
1. make the divs fixed height/width, then stuff in the images with an overflow:none , and center the image horizontally/vertically within the div....
Read more >Resizing or Scaling -- IM v6 Examples - ImageMagick
The most obvious and common way to change the size of an image is to resize or scale an image. The content of...
Read more >Resizing background images with background-size - CSS
The background-size CSS property lets you resize the background ... To do this, we can use a fixed background-size value of 150 pixels....
Read more >How to Adjust Enlarge and Edit Image Size in ... - YouTube
This Microsoft Word 2016 tutorial shows you how to resize pictures and images in MS Office 365. I show how to increase and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I did the html5 canvas method. Since individual alignedFaceImages element is a HTML canvas just create a new canvas children with size I wanted, then draw the alignedFaceImages[i] into the new canvas context inside the forEach loop.
i know the approach is rather simple not sure about the optimization since this is just POC.
Not familiar with the tensor method though, it is possible to use tf function within js?
Just in case if somebody looking for a canvas without “stretching” the image, you can do x,y offsets. My solution is like below
faceImages.forEach((face)=>{ var res = canvas.createCanvas(200, 200) let h = face.height; let w = face.width; let a = 0; let b = 0; if (h <= 200 && w <= 200) { a = (200 - w) / 2; b = (200 - h) / 2; res.getContext(“2d”).drawImage(face, a, b, w, h) } else { res.getContext(“2d”).drawImage(face, 0, 0, 200, 200) } //save or display canvas })