-
-
Save mathewthe2/0b259fe8e511e32f0ac8531be8bc2e4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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