Skip to content

Instantly share code, notes, and snippets.

@mathewthe2
Created November 24, 2020 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathewthe2/0b259fe8e511e32f0ac8531be8bc2e4f to your computer and use it in GitHub Desktop.
Save mathewthe2/0b259fe8e511e32f0ac8531be8bc2e4f to your computer and use it in GitHub Desktop.
const confidence = 0.8; // Confidence range is 0 to 1
async function predict() {
...
const prediction = await model.predict(posenetOutput);
for (let i = 0; i < maxPredictions; i++) {
const classPrediction = prediction[i].className + ": " + prediction[i].probability.toFixed(2);
// Insert the API call here
if (prediction[i].probability > confidence) {
callReaction(prediction[i].className);
}
labelContainer.childNodes[i].innerHTML = classPrediction;
}
// finally draw the poses
drawPose(pose);
};
let clapping = 0;
const threshold = 5; // number of times of detection to run API
async function callReaction(predictionClassName) {
if (predictionClassName == 'Clapping') {
clapping += 1
if (clapping > threshold) {
fetch('https://myapi.com/?reaction=Clapping'); // Change to your own API endpoint
clapping = 0; // reset for threshold
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment