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.
This commit is contained in:
Peter Braden 2013-02-26 15:26:54 -08:00
parent 3a7469fe52
commit 0cb436e930
3 changed files with 43 additions and 12 deletions

View File

@ -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.ImageDataStream()
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('load', function(matrix){
...
})
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 File

@ -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 File

@ -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)