
    await detectOnCanvas();
  };
  img.src = url;
  file.value = '';
};

async function tick() {
  if (!recording) return;

  if (video.readyState === video.HAVE_ENOUGH_DATA) {
    const scale = Math.min(canvas.width / video.videoWidth, canvas.height / video.videoHeight);
    const w = video.videoWidth * scale;
    const h = video.videoHeight * scale;

    ctx.drawImage(video, (canvas.width - w) / 2, (canvas.height - h) / 2, w, h);

    await detectOnCanvas();
  }

  requestAnimationFrame(tick);
}

camera.