async function detectAndAnnotateVideo(webcamCanvas, detector) {
const [video, ctx, imgHeight, imgWidth] = webcamCanvas;
const estimationConfig = { flipHorizontal: true };
const hands = await detector.estimateHands(video, estimationConfig);
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
if (hands.length != 0) {
if (hands[0].score >= 0.5) {
webCamMessage.querySelector("#status").innerHTML = "";
webCamMessage.querySelector("#status").className = "";
ctx.fillText(
`${hands[0].handedness} Hand, Score: ${hands[0].score}`,
d3.mean(hands[0].keypoints.map((kp) => kp.x)),
d3.mean(hands[0].keypoints.map((kp) => kp.y))
);
}
}
requestAnimationFrame(() => {
detectAndAnnotateVideo(webcamCanvas, detector);
});
}