Allow video capture to be streamed

This commit is contained in:
Peter Braden 2013-02-26 19:07:39 -08:00
parent c3d3f0f4b4
commit f2ec2cd3ed

View File

@ -69,7 +69,6 @@ imagedatastream.end = function(b){
} }
<<<<<<< HEAD
cv.ImageStream = function(){ cv.ImageStream = function(){
this.writable = true this.writable = true
@ -88,7 +87,9 @@ imagestream.write = function(buf){
// Object detect stream // Object detect stream
cv.ObjectDetectionStream = function(cascade, opts){ cv.ObjectDetectionStream = function(cascade, opts){
this.classifier = new cv.CascadeClassifier(cascade); this.classifier = new cv.CascadeClassifier(cascade);
this.opts = opts this.opts = opts || {}
this.readable = true;
this.writable = true;
} }
util.inherits(cv.ObjectDetectionStream, Stream); 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]); , 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. // Provide cascade data for faces etc.
cv.FACE_CASCADE = path.resolve(__dirname, '../data/haarcascade_frontalface_alt.xml')
cv.FACE_CASCADE = path.resolve('./data/haarcascade_frontalface_alt.xml')