Skip to content
Browse files

Allow video capture to be streamed

  • Loading branch information...
1 parent c3d3f0f commit f2ec2cd3edf9211a566fa0f44d22e5ef853cce81 @peterbraden committed Feb 26, 2013
Showing with 46 additions and 4 deletions.
  1. +46 −4 lib/opencv.js
View
50 lib/opencv.js
@@ -69,7 +69,6 @@ imagedatastream.end = function(b){
}
-<<<<<<< HEAD
cv.ImageStream = function(){
this.writable = true
@@ -88,7 +87,9 @@ imagestream.write = function(buf){
// Object detect stream
cv.ObjectDetectionStream = function(cascade, opts){
this.classifier = new cv.CascadeClassifier(cascade);
- this.opts = opts
+ this.opts = opts || {}
+ this.readable = true;
+ this.writable = true;
}
util.inherits(cv.ObjectDetectionStream, Stream);
@@ -106,10 +107,51 @@ ods.write = function(m){
, this.opts.min && this.opts.min[0], this.opts.min && this.opts.min[1]);
}
+// == Video Stream ==
+cv.VideoStream = function(src){
+ if (src instanceof cv.VideoCapture){
+ this.video = src
+ } else {
+ this.video = new cv.VideoCapture(src);
+ }
+ this.readable = true;
+ this.paused = false;
+}
+util.inherits(cv.VideoStream, Stream);
+var videostream = cv.VideoStream.prototype;
+cv.VideoCapture.prototype.toStream = function(){
+ return new cv.VideoStream(this);
+}
-// Provide cascade data for faces etc.
+videostream.read = function(){
+ var self = this;
+
+ var frame = function(){
+ self.video.read(function(mat){
+ self.emit('data', mat)
+ if (!this.paused){
+ process.nextTick(frame)
+ }
+
+ })
+ }
-cv.FACE_CASCADE = path.resolve('./data/haarcascade_frontalface_alt.xml')
+ frame();
+}
+
+videostream.pause = function(){
+ this.paused = true
+}
+
+videostream.resume = function(){
+ this.paused = false
+ this.read()
+}
+
+
+
+// Provide cascade data for faces etc.
+cv.FACE_CASCADE = path.resolve(__dirname, '../data/haarcascade_frontalface_alt.xml')

0 comments on commit f2ec2cd

Please sign in to comment.
Something went wrong with that request. Please try again.