From 862a31eb2aaa07c57797d73ed7e4c8168c67a65d Mon Sep 17 00:00:00 2001 From: Peter Braden Date: Wed, 15 Oct 2014 20:54:58 +0200 Subject: [PATCH] Tidy up lib --- lib/opencv.js | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/opencv.js b/lib/opencv.js index 3eb92e7..dc043a0 100755 --- a/lib/opencv.js +++ b/lib/opencv.js @@ -4,8 +4,13 @@ var Stream = require('stream').Stream , path = require('path'); var cv = module.exports = require('./bindings'); -var Matrix = cv.Matrix, VideoCapture = cv.VideoCapture, - ImageStream, ImageDataStream, ObjectDetectionStream, VideoStream; + +var Matrix = cv.Matrix + , VideoCapture = cv.VideoCapture + , ImageStream + , ImageDataStream + , ObjectDetectionStream + , VideoStream; Matrix.prototype.detectObject = function(classifier, opts, cb){ @@ -29,8 +34,7 @@ Matrix.prototype.inspect = function(){ } -ImageStream = -cv.ImageStream = function(){ +ImageStream = cv.ImageStream = function(){ this.writable = true; } util.inherits(ImageStream, Stream); @@ -45,8 +49,7 @@ ImageStream.prototype.write = function(buf){ } -ImageDataStream = -cv.ImageDataStream = function(){ +ImageDataStream = cv.ImageDataStream = function(){ this.data = Buffers([]); this.writable = true; } @@ -71,8 +74,7 @@ ImageDataStream.prototype.end = function(b){ } -ObjectDetectionStream = -cv.ObjectDetectionStream = function(cascade, opts){ +ObjectDetectionStream = cv.ObjectDetectionStream = function(cascade, opts){ this.classifier = new cv.CascadeClassifier(cascade); this.opts = opts || {}; this.readable = true; @@ -94,8 +96,7 @@ ObjectDetectionStream.prototype.write = function(m){ } -VideoStream = -cv.VideoStream = function(src){ +VideoStream = cv.VideoStream = function(src){ if (!(src instanceof VideoCapture)) src = new VideoCapture(src); this.video = src; this.readable = true; @@ -134,5 +135,19 @@ VideoCapture.prototype.toStream = function(){ } + // Provide cascade data for faces etc. -cv.FACE_CASCADE = path.resolve(__dirname, '../data/haarcascade_frontalface_alt.xml') +var CASCADES = { + FACE_CASCADE: 'haarcascade_frontalface_alt.xml' +, EYE_CASCADE: 'haarcascade_eye.xml' +, EYEGLASSES_CASCADE: 'haarcascade_eye_tree_eyeglasses.xml' +, FULLBODY_CASCADE: 'haarcascade_fullbody.xml' +, CAR_SIDE_CASCADE: 'hogcascade_cars_sideview.xml' +} + +Object.keys(CASCADES).forEach(function(k){ + cv[k] = path.resolve(__dirname, '../data', CASCADES[k]) +}) + + +