face-recognition.js
face-recognition.js copied to clipboard
Filter windows must be small enough to fit into the padded image
I have this code that gets an image URL and attempts to detect faces, but it keeps failing with an error saying that it is too big or something (see error below).
let cv = require('opencv4nodejs');
let fr = require('face-recognition').withCv(cv);
var request = require('request');
const detector = fr.AsyncFaceDetector();
const recognizer = fr.FaceRecognizer();
request(url, function (error, response, body) {
let buffer = Buffer.from(body);
let imageCvMat = cv.imdecode(buffer);
let imageCv = fr.CvImage(imageCvMat);
let imageRgb = fr.cvImageToImageRGB(imageCv);
detector.detectFaces(imageRgb).then(function (faces) {
console.log(faces.length)
});
});
**************************** FATAL ERROR DETECTED ****************************
Error detected at line 1971.
Error detected in file /Users/botvinick/Desktop/GitHub/api.benbotvinick.com/node_modules/dlib-build/dlib/dlib/dlib/dnn/cpu_dlib.cpp.
Error detected in function void dlib::cpu::tensor_conv::operator()(const bool, dlib::tensor &, const dlib::tensor &, const dlib::tensor &).
Failing expression was filters.nr() <= data.nr() + 2*last_padding_y.
Filter windows must be small enough to fit into the padded image.
******************************************************************************
libc++abi.dylib: terminate_handler unexpectedly returned
Could you log the dimensions of your images? My guess is, that some of them are simply too small or maybe something went wrong when decoding the image content.
I think you can not put any images smaller than ~105x105 into the net.
Yes, that seems to be the issue. I was attempting to load the images from a URL, and I think it's more than likely they were truncated when I was converting them to ImageRGB
. I ended up downloading the images temporarily from URL with a different package before processing them and that worked. However, it is a bit unreliable (my dimensions are 256x256) depending on the image. Thanks anyway though.