如何使用node和openCV停止videoccapture()



我想从Node.js停止videocapture。我该怎么做呢?

var cv = require('opencv');
var camWidth = 640;
var camHeight = 480;
var camFps = 40;
var camInterval = 1000 / camFps;
camera = new cv.VideoCapture(0);
camera.setWidth(camWidth);
camera.setHeight(camHeight);
camera.read(function(err, im) {
   if (err) throw err;
   ...
}

现在,我想要停止videoCapture…

您试过调用release()吗?http://docs.opencv.org/3.2.0/d8/dfe/classcv_1_1VideoCapture.html afb4ab689e553ba2c8f0fec41b9344ae6

在你的例子中应该是:

camera.release();

你可以使用时间来停止你的相机,就像这个例子

///stop camera after 10 seconds
function isTimerFinished(timeBeforeExecute) {
    var currentTime = new Date().getTime() / 1000;
    return (currentTime < timeBeforeExecute + 10)
}

 var timeBeforeExecute = new Date().getTime() / 1000; 

var video = setInterval(function () {
        if (isTimerFinished(timeBeforeExecute)) {
            const frame = wCap.read();
            const image = cv.imencode('.jpg', frame).toString('base64');
            io.emit('image', image)
        } else {
            image = '../public/img/image.jpg';
            io.emit('image', image)
            clearInterval(video);
        }
    }, 1000 / FPS);

相关内容

  • 没有找到相关文章

最新更新