【发布时间】:2020-07-24 00:42:33
【问题描述】:
我正在制作一个程序,如果我的网络摄像头检测到我的手(来自 Handtrack.js),就会弹出一个文本和一个图像。问题是,只要我的手在场,它就会重复执行(这是有道理的)。如何让它只运行一次?
function runDetection(){
model.detect(video).then(predictions => {
console.log(predictions);
model.renderPredictions(predictions, canvas, context, video);
let handSign = predictions[0].bbox;
let width = handSign[2];
let height = handSign[3];
if( (width >= 100 && width < 140) && (height >=150 && height < 200)){
//how to call this once??
sendApiRequest()
}
/*else if ((width >= 300 && width < 400) && (height >=300 && height < 400)){
sendApiRequest2()
}*/
});
}
【问题讨论】:
-
您可以在函数范围之外创建一个布尔值以在条件中使用,并在 if 语句中将其设置为 false
-
由于某种原因不起作用
标签: javascript function