Permalink
Browse files

unit test for imagestream

  • Loading branch information...
1 parent 0cb436e commit 24f255a1614d4394da3675f50bae1cced8302512 @peterbraden committed Feb 27, 2013
Showing with 45 additions and 0 deletions.
  1. +22 −0 lib/opencv.js
  2. +23 −0 test/unit.js
View
@@ -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]);
+}
+
View
@@ -273,6 +273,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" : {

0 comments on commit 24f255a

Please sign in to comment.