1

我试图使用 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;**
4

1 回答 1

2

从这个参考,这应该工作;

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;
  }

});
于 2020-01-05T07:19:16.740 回答