diff --git a/public/js/draw.js b/public/js/draw.js index 8bd493f..649c892 100644 --- a/public/js/draw.js +++ b/public/js/draw.js @@ -44,7 +44,6 @@ function drawFrame(canvas, video, combinedFeatures) { } const faceMeshes = combinedFeatures[0]; - const handPoses = combinedFeatures[1]; const ctx = canvas.getContext('2d'); ctx.drawImage( @@ -67,8 +66,9 @@ function drawFrame(canvas, video, combinedFeatures) { } // Render HandPose - let handPoints; - if (handPoses !== undefined && handPoses.length > 0) { + let handPoints = null; + if (combinedFeatures[1] !== null) { + const handPoses = combinedFeatures[1]; handPoints = handPoses[0].landmarks; const handAnnotations = handPoses[0].annotations; drawPoints(ctx, handPoints, 3); diff --git a/public/js/main.js b/public/js/main.js index 91b5018..4daffe7 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -123,11 +123,11 @@ function processKeyPoints(combinedKeyPoints) { } if (state.isInferenceOn) { - if (facePoints !== undefined && handPoints !== undefined) { + if (handPoints !== null) { computeInference(facePoints, handPoints).then((inference) => updateInferenceText(inference[0]) ); - } + } else updateInferenceText(0); } else if (!state.isInDevMode) { document.getElementById('inference-txt').innerHTML = '- %'; } diff --git a/public/js/models.js b/public/js/models.js index dca791b..e0b2474 100644 --- a/public/js/models.js +++ b/public/js/models.js @@ -86,10 +86,13 @@ async function computeCombinedKeyPoints(video) { throw Error('Cannot compute key points for undefined video stream'); } - return Promise.all([ + const combinedFeatures = await Promise.all([ faceMesh.estimateFaces(video), handPose.estimateHands(video), ]); + + const noHandFound = !combinedFeatures[1].length; + return noHandFound ? [combinedFeatures[0], null] : combinedFeatures; } /*