I am capturing poses every second, but when I change the state of the variable, the site crashes, console.log() goes crazy fast, 10-20 times in a second.
Shortened code:
const runPose = async () => {
const detector = await poseDetection.createDetector(
poseDetection.SupportedModels.MoveNet,
{modelType: poseDetection.movenet.modelType.SINGLEPOSE_THUNDER,}
);
setInterval(() => {detect(detector)}, 1000); // This function's the problem
};
Problem:
const detect = async (net: any) => {
const poses = await net.estimatePoses(video);
const kp = poses[0].keypoints
const sum = Math.abs(kp[6].y - kp[12].y)
setstate(sum) // if I don't do this, the website's fine.
// if I do, console.log() happens 10-20 times a second
console.log('hi')
}
function App() {
runPose();
}