다음과 같이 동작 구분시 알림음을 주고 싶다면
자바스크립트 코드에서 predict 함수를 수정해줍니다!
async function predict() {
// Prediction #1: run input through posenet
// estimatePose can take in an image, video or canvas html element
const { pose, posenetOutput } = await model.estimatePose(webcam.canvas);
// Prediction 2: run input through teachable machine classification model
const prediction = await model.predict(posenetOutput);
for (let i = 0; i < maxPredictions; i++) {
const classPrediction =
prediction[i].className + ": " + prediction[i].probability.toFixed(2);
// don't play audio when head's neutral with probability >= 75%
if (prediction[0].probability.toFixed(2) >= 0.30)
pauseAud();
else
playAud();
}
// finally draw the poses
drawPose(pose);
}
만약 라벨에도 내용을 다르게 해주고 싶다면 이전 게시물을 참고해주세요
모든 것을 다 한 코드는 다음과 같습니다
async function predict() {
// Prediction #1: run input through posenet
// estimatePose can take in an image, video or canvas html element
const { pose, posenetOutput } = await model.estimatePose(webcam.canvas);
// Prediction 2: run input through teachable machine classification model
const prediction = await model.predict(posenetOutput);
for (let i = 0; i < maxPredictions; i++) {
const classPrediction =
prediction[i].className + ": " + prediction[i].probability.toFixed(2);
// don't play audio when head's neutral with probability >= 75%
if (prediction[0].probability.toFixed(2) >= 0.30)
pauseAud();
else
playAud();
if(prediction[0].probability.toFixed(2)==1.00){
labelContainer.childNodes[0].innerHTML = "바른 자세입니다. 지금 자세를 유지하세요.";
}
else if(prediction[1].probability.toFixed(2)==1.00){
labelContainer.childNodes[0].innerHTML = "얼굴이 오른쪽으로 기울었습니다. 바른 자세를 유지하세요.";
//alert('바른자세를 유지하세여');
}
else if(prediction[2].probability.toFixed(2)==1.00){
labelContainer.childNodes[0].innerHTML = "얼굴이 왼쪽으로 기울었습니다. 바른 자세를 유지하세요.";
}
else if(prediction[3].probability.toFixed(2)==1.00){
labelContainer.childNodes[0].innerHTML = "거북목 자세입니다. 바른 자세를 유지하세요.";
}
else if(prediction[4].probability.toFixed(2)==1.00){
labelContainer.childNodes[0].innerHTML = "오른쪽 어깨가 올라갔습니다. 바른 자세를 유지하세요.";
}
else if(prediction[5].probability.toFixed(2)==1.00){
labelContainer.childNodes[0].innerHTML = "왼쪽 어깨가 올라갔습니다. 바른 자세를 유지하세요.";
}
}
// finally draw the poses
drawPose(pose);
}