Face recognition in javascript using face api getting "Uncaught (in promise) TypeError: Cannot read property 'descriptor' of undefined"
Face recognition in javascript using face api getting "Uncaught (in promise) TypeError: Cannot read property 'descriptor' of undefined"
在使用node js 的web 应用程序的浏览器的网络摄像头摄像头上实现人脸识别时遇到这个问题。仅当我在 loadLabeledImages() 函数的标签中添加超过 1 个名称时才会出现此错误。如果我有一个名字,它工作得很好。这里是初学者,我几天来一直遇到同样的错误
如果我记录调整大小的检测和检测,我得到这个:
Error after logging detections and resized detections
感谢任何帮助,非常感谢!
setInterval(async () => {
const detections = await faceapi.detectSingleFace(video).withFaceLandmarks().withFaceDescriptor()
const resizedDetections = faceapi.resizeResults(detections, displaySize)
canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height)
faceapi.draw.drawFaceLandmarks(canvas, resizedDetections)
this.labeledFaceDescriptors = await this.loadLabeledImages()
const faceMatcher = new faceapi.FaceMatcher(labeledFaceDescriptors, 0.6)
const results = resizedDetections.map(d => faceMatcher.findBestMatch(d.descriptor))
results.forEach((result, i) => {
const box = resizedDetections[i].detection.box
const drawBox = new faceapi.draw.DrawBox(box, {label: result.toString()})
drawBox.draw(canvas)
})
}, 100)
})
function loadLabeledImages() {
try{
const labels = ['Jane', 'Alex']
return Promise.all(
labels.map(async label => {
const descriptions = []
for (let i = 1; i <= 3; i++) {
const img = await faceapi.fetchImage(`public/img/${label}/${i}.jpg`)
const detections = await faceapi.detectSingleFace(img).withFaceLandmarks().withFaceDescriptor()
descriptions.push(detections.descriptor)
}
return new faceapi.LabeledFaceDescriptors(label, this.descriptions)
})
)
}
catch(err){
console.log(err)
}
}
'descriptor' 值未定义..因此你得到错误
抱歉延迟,我的问题已经通过更改图像解决了。错误是因为它无法在我提供的图像中识别人脸(描述符)。我检查了图像的质量,这非常糟糕,所以我将它们更改为质量好的图像,错误消失了。
在使用node js 的web 应用程序的浏览器的网络摄像头摄像头上实现人脸识别时遇到这个问题。仅当我在 loadLabeledImages() 函数的标签中添加超过 1 个名称时才会出现此错误。如果我有一个名字,它工作得很好。这里是初学者,我几天来一直遇到同样的错误
如果我记录调整大小的检测和检测,我得到这个: Error after logging detections and resized detections
感谢任何帮助,非常感谢!
setInterval(async () => {
const detections = await faceapi.detectSingleFace(video).withFaceLandmarks().withFaceDescriptor()
const resizedDetections = faceapi.resizeResults(detections, displaySize)
canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height)
faceapi.draw.drawFaceLandmarks(canvas, resizedDetections)
this.labeledFaceDescriptors = await this.loadLabeledImages()
const faceMatcher = new faceapi.FaceMatcher(labeledFaceDescriptors, 0.6)
const results = resizedDetections.map(d => faceMatcher.findBestMatch(d.descriptor))
results.forEach((result, i) => {
const box = resizedDetections[i].detection.box
const drawBox = new faceapi.draw.DrawBox(box, {label: result.toString()})
drawBox.draw(canvas)
})
}, 100)
})
function loadLabeledImages() {
try{
const labels = ['Jane', 'Alex']
return Promise.all(
labels.map(async label => {
const descriptions = []
for (let i = 1; i <= 3; i++) {
const img = await faceapi.fetchImage(`public/img/${label}/${i}.jpg`)
const detections = await faceapi.detectSingleFace(img).withFaceLandmarks().withFaceDescriptor()
descriptions.push(detections.descriptor)
}
return new faceapi.LabeledFaceDescriptors(label, this.descriptions)
})
)
}
catch(err){
console.log(err)
}
}
'descriptor' 值未定义..因此你得到错误
抱歉延迟,我的问题已经通过更改图像解决了。错误是因为它无法在我提供的图像中识别人脸(描述符)。我检查了图像的质量,这非常糟糕,所以我将它们更改为质量好的图像,错误消失了。