Permalink
Browse files

Changing ImageStream -> ImageDataStream and creating ImageStream.

To pipe data into an image matrix, you now use ImageDataStream.

ImageStream is now a stream that transforms image buffers into matrices.
  • Loading branch information...
1 parent 3a7469f commit 0cb436e930b8d46f6fb2c68944be8d8801307750 @peterbraden committed Feb 26, 2013
Showing with 43 additions and 12 deletions.
  1. +20 −5 README.md
  2. +21 −5 lib/opencv.js
  3. +2 −2 test/unit.js
View
@@ -65,15 +65,30 @@ Or you can use opencv to read in image files. Supported formats are in the OpenC
...
})
-If you need to pipe data into an image, you can use an imagestream:
+If you need to pipe data into an image, you can use an ImageDataStream:
- var s = new cv.ImageStream()
+ var s = new cv.ImageDataStream()
- s.on('load', function(matrix){
+ s.on('load', function(matrix){
...
- })
+ })
+
+ fs.createReadStream('./examples/test.jpg').pipe(s);
+
+If however, you have a series of images, and you wish to stream them into a
+stream of Matrices, you can use an ImageStream. Thus:
+
+ var s = new cv.ImageStream()
+
+ s.on('data', function(matrix){
+ ...
+ })
+
+ ardrone.createPngStream().pipe(s);
+
+Note: Each 'data' event into the ImageStream should be a complete image buffer.
+
- fs.createReadStream('./examples/test.jpg').pipe(s);
#### Accessing Data
View
@@ -40,21 +40,21 @@ matrix.inspect = function(){
}
-cv.ImageStream = function(){
+cv.ImageDataStream = function(){
this.data = Buffers([])
this.writable = true
}
-util.inherits(cv.ImageStream, Stream);
-var imagestream = cv.ImageStream.prototype;
+util.inherits(cv.ImageDataStream, Stream);
+var imagedatastream = cv.ImageDataStream.prototype;
-imagestream.write = function(buf){
+imagedatastream.write = function(buf){
this.data.push(buf)
return true;
}
-imagestream.end = function(b){
+imagedatastream.end = function(b){
var self = this;
if (b)
@@ -67,3 +67,19 @@ imagestream.end = function(b){
});
}
+
+
+cv.ImageStream = function(){
+ this.writable = true
+}
+
+util.inherits(cv.ImageStream, Stream);
+var imagestream = cv.ImageStream.prototype;
+
+imagestream.write = function(buf){
+ cv.readImage(buf, function(err, matrix){
+ self.emit('data', matrix);
+ });
+}
+
+
View
@@ -250,12 +250,12 @@ vows.describe('Smoke Tests OpenCV').addBatch({
}
- , "ImageStream" : {
+ , "ImageDataStream" : {
topic : require('../lib/opencv')
, "pipe" : {
topic : function(cv){
- var s = new cv.ImageStream()
+ var s = new cv.ImageDataStream()
, self = this
s.on('load', function(im){
assert.ok(im)

0 comments on commit 0cb436e

Please sign in to comment.