diff --git a/lib/opencv.js b/lib/opencv.js index 4c83066..949137c 100755 --- a/lib/opencv.js +++ b/lib/opencv.js @@ -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')