Skip to content

Commit

Permalink
unit test for imagestream
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbraden committed Feb 27, 2013
1 parent 0cb436e commit 24f255a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/opencv.js
Expand Up @@ -77,9 +77,31 @@ util.inherits(cv.ImageStream, Stream);
var imagestream = cv.ImageStream.prototype; var imagestream = cv.ImageStream.prototype;


imagestream.write = function(buf){ imagestream.write = function(buf){
var self = this;
cv.readImage(buf, function(err, matrix){ cv.readImage(buf, function(err, matrix){
self.emit('data', 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]);
}



23 changes: 23 additions & 0 deletions test/unit.js
Expand Up @@ -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" : { , "CamShift" : {
Expand Down

0 comments on commit 24f255a

Please sign in to comment.