Face Recognition on Webcam Implementation: Cannot read property 'descriptor' of undefined
See original GitHub issueUrgent: Facing this issue in the implementation of face recognition on the webcam camera for the browser. This error only comes when I add more than 1 name in my labels in loadLabeledImages() function. If I have one name, it works perfectly fine. Any help is appreciated. This is a part of a project that has to be completed in a week! Thank you so much!
Getting “Uncaught (in promise) TypeError: Cannot read property ‘descriptor’ of undefined”
This is the code for your reference:
`
const video = document.getElementById('video')
Promise.all([
faceapi.nets.tinyFaceDetector.loadFromUri('/models'),
faceapi.nets.faceLandmark68Net.loadFromUri('/models'),
faceapi.nets.faceRecognitionNet.loadFromUri('/models'),
faceapi.nets.ssdMobilenetv1.loadFromUri('/models'),
]).then(startVideo)
function startVideo() {
navigator.getUserMedia(
{ video: {} },
stream => video.srcObject = stream,
err => console.error(err)
)
}
this.video.addEventListener('play',() => {
const canvas = faceapi.createCanvasFromMedia(video)
document.body.append(canvas)
const displaySize = { width: video.width, height: video.height }
faceapi.matchDimensions(canvas, displaySize)
setInterval(async () => {
const detections = await faceapi.detectAllFaces(video).withFaceLandmarks().withFaceDescriptors()
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 = ['Shriya', 'judhi']
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)
}
}`
Issue Analytics
- State:
- Created 3 years ago
- Comments:12
Top Results From Across the Web
cannot read property 'descriptor' of undefined - CodeProject
Face recognition on webcam implementation: cannot read property 'descriptor' of undefined.
Read more >Face recognition in javascript using face api getting "Uncaught ...
Face recognition in javascript using face api getting "Uncaught (in promise) TypeError: Cannot read property 'descriptor' of undefined".
Read more >face-api.js
JavaScript API for face detection and face recognition in the browser implemented on top of the tensorflow.js core API (tensorflow/tfjs-core).
Read more >Unanswered 'Faceapi' Questions - ADocLib
Face recognition on webcam implementation: cannot read property 'descriptor' of undefined ; const video document.getElementById' ; 3 Promise.
Read more >Face Detection in Python Using a Webcam
This tutorial is a follow-up to Face Recognition in Python, ... This doesn't matter when reading from the webcam, since we can record...
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
It is because your label image doesn’t detect any face. You need to ensure the images are person face
Not yet. just have 1 solution above.