mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Allow video capture to be streamed
This commit is contained in:
parent
c3d3f0f4b4
commit
f2ec2cd3ed
@ -69,7 +69,6 @@ imagedatastream.end = function(b){
|
||||
}
|
||||
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
cv.ImageStream = function(){
|
||||
this.writable = true
|
||||
@ -88,7 +87,9 @@ imagestream.write = function(buf){
|
||||
// Object detect stream
|
||||
cv.ObjectDetectionStream = function(cascade, opts){
|
||||
this.classifier = new cv.CascadeClassifier(cascade);
|
||||
this.opts = opts
|
||||
this.opts = opts || {}
|
||||
this.readable = true;
|
||||
this.writable = true;
|
||||
}
|
||||
|
||||
util.inherits(cv.ObjectDetectionStream, Stream);
|
||||
@ -106,10 +107,51 @@ ods.write = function(m){
|
||||
, this.opts.min && this.opts.min[0], this.opts.min && this.opts.min[1]);
|
||||
}
|
||||
|
||||
// == Video Stream ==
|
||||
cv.VideoStream = function(src){
|
||||
if (src instanceof cv.VideoCapture){
|
||||
this.video = src
|
||||
} else {
|
||||
this.video = new cv.VideoCapture(src);
|
||||
}
|
||||
this.readable = true;
|
||||
this.paused = false;
|
||||
}
|
||||
|
||||
util.inherits(cv.VideoStream, Stream);
|
||||
var videostream = cv.VideoStream.prototype;
|
||||
cv.VideoCapture.prototype.toStream = function(){
|
||||
return new cv.VideoStream(this);
|
||||
}
|
||||
|
||||
videostream.read = function(){
|
||||
var self = this;
|
||||
|
||||
var frame = function(){
|
||||
self.video.read(function(mat){
|
||||
self.emit('data', mat)
|
||||
if (!this.paused){
|
||||
process.nextTick(frame)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
frame();
|
||||
}
|
||||
|
||||
videostream.pause = function(){
|
||||
this.paused = true
|
||||
}
|
||||
|
||||
videostream.resume = function(){
|
||||
this.paused = false
|
||||
this.read()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Provide cascade data for faces etc.
|
||||
|
||||
cv.FACE_CASCADE = path.resolve('./data/haarcascade_frontalface_alt.xml')
|
||||
cv.FACE_CASCADE = path.resolve(__dirname, '../data/haarcascade_frontalface_alt.xml')
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user