gpt4 book ai didi

jquery - Mozilla 和 Safari 中的人脸检测.js IndexSIzeError

转载 作者:行者123 更新时间:2023-12-01 05:23:51 24 4
gpt4 key购买 nike

我正在尝试检测图像中的面部。我只需要用户选择的图像中的面孔数量。我使用以下代码将图像从输入字段加载到预览 div 中:

function readURL(input) {
if (input.files && input.files[0]) {
var image = new FileReader();

image.onloadend = function (e) {
$('#image-wrap').html('<img src="" id="uploaded-photo">');
$('#uploaded-photo').attr('src', e.target.result);
$('#uploaded-photo').fadeIn();
facedetect();
}

image.readAsDataURL(input.files[0]);
}
}

$("#userfile").change(function() {
readURL(this);
});

检测的函数就是这个

function facedetect() {
$('#uploaded-photo').faceDetection({
complete: function (faces) {
console.log(faces);
},
error: function (code, message) {
console.log(message);
}
});
}

这在 Chrome 中工作得很好,但在 Mozilla 和 Safari 中的某些情况下(尽管不是全部),我在控制台中得到了这个:

IndexSizeError: Index or size is negative or greater than the allowed amount

生成这个的行似乎是这个:

var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);

非常感谢任何帮助。

最佳答案

似乎我的图像没有完全加载,因此在加载事件中调用faceDetect解决了问题

$('#uploaded-photo').on('load',function(){ facedetect(); });

感谢所有试图帮助我的人:)

关于jquery - Mozilla 和 Safari 中的人脸检测.js IndexSIzeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40991646/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com