【问题标题】:Can anyone tell me how to trigger a function when the mouse is pressed and continues untill it is released in p5.js谁能告诉我当鼠标被按下时如何触发一个函数并继续直到它在 p5.js 中被释放
【发布时间】:2020-04-23 03:29:41
【问题描述】:

我试图使用 p5 和 ml5 添加图像 在我的网站中,用户可以在那里训练自己的图像并通过网络摄像头获得预测输出

var addImage;
var mobilenet;
mobilenet = ml5.featureExtractor('MobileNet', modelReady);
classifier = mobilenet.classification(video,videoReady);
addImage = createButton('Insert');
addImage.mousePressed(function (){
classifier.addImage('Insert');
});

但是对于每张图片,我都需要按下鼠标按钮来插入我只想让它像这样

**On mousePress()
  function to add multiple image;
  On mouseRelease()
  stop;**

【问题讨论】:

    标签: javascript machine-learning p5.js web-site-project mobilenet


    【解决方案1】:

    从这个reference,这应该可以工作;

    var addImage;
    var mobilenet;
    var drawImageInterval = null;
    mobilenet = ml5.featureExtractor('MobileNet', modelReady);
    classifier = mobilenet.classification(video,videoReady);
    addImage = createButton('Insert');
    addImage.mousePressed(function (){
       if(mouseIsPressed && !drawImageInterval){
         drawImageInterval = setInterval(function(){
             classifier.addImage('Insert');
          }, 1000);
      } else {
         clearInterval(drawImageInterval);
         drawImageInterval = null;
      }
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多