diff --git a/lib/opencv.js b/lib/opencv.js index 5a155e6..9f2a91f 100755 --- a/lib/opencv.js +++ b/lib/opencv.js @@ -77,9 +77,31 @@ util.inherits(cv.ImageStream, Stream); var imagestream = cv.ImageStream.prototype; imagestream.write = function(buf){ + var self = this; cv.readImage(buf, function(err, matrix){ self.emit('data', matrix); }); } +// Object detect stream +cv.ObjectDetectionStream = function(cascade, opts){ + this.classifier = new cv.CascadeClassifier(cascade); + this.opts = opts +} + +util.inherits(cv.ObjectDetectionStream, Stream); +var ods = cv.ObjectDetectionStream.prototype; + +ods.write = function(m){ + var self = this; + + this.classifier.detectMultiScale(m, + function(e, objs){ + if (e) { throw e } + self.emit('data', objs); + } + , this.opts.scale, this.opts.neighbors + , this.opts.min && this.opts.min[0], this.opts.min && this.opts.min[1]); +} + diff --git a/test/unit.js b/test/unit.js index b10ff9f..df4ede9 100755 --- a/test/unit.js +++ b/test/unit.js @@ -272,6 +272,29 @@ vows.describe('Smoke Tests OpenCV').addBatch({ } + } + , "ImageStream" :{ + topic : require('../lib/opencv') + , "write" : { + topic: function(cv){ + var s = new cv.ImageStream() + , im = fs.readFileSync('./examples/mona.png') + , self = this; + + s.on('data', function(m){ + self.callback(null, m) + }) + s.write(im); + } + , "receives data" : function(mat){ + assert.deepEqual(mat.size(), [756,500]) + } + } + + } + , "ObjectDetectionStream" :{ + topic : require('../lib/opencv') + } , "CamShift" : {