任何人都可以告诉我如何在按下鼠标时触发一个功能并继续直到它在 p5.js 中被释放
Can anyone tell me how to trigger a function when the mouse is pressed and continues untill it is released in p5.js
我尝试使用 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;**
据此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;
}
});
我尝试使用 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;**
据此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;
}
});