Tidy up lib

This commit is contained in:
Peter Braden 2014-10-15 20:54:58 +02:00
parent b9fbf5f526
commit 862a31eb2a

View File

@ -4,8 +4,13 @@ var Stream = require('stream').Stream
, path = require('path'); , path = require('path');
var cv = module.exports = require('./bindings'); 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){ Matrix.prototype.detectObject = function(classifier, opts, cb){
@ -29,8 +34,7 @@ Matrix.prototype.inspect = function(){
} }
ImageStream = ImageStream = cv.ImageStream = function(){
cv.ImageStream = function(){
this.writable = true; this.writable = true;
} }
util.inherits(ImageStream, Stream); util.inherits(ImageStream, Stream);
@ -45,8 +49,7 @@ ImageStream.prototype.write = function(buf){
} }
ImageDataStream = ImageDataStream = cv.ImageDataStream = function(){
cv.ImageDataStream = function(){
this.data = Buffers([]); this.data = Buffers([]);
this.writable = true; this.writable = true;
} }
@ -71,8 +74,7 @@ ImageDataStream.prototype.end = function(b){
} }
ObjectDetectionStream = ObjectDetectionStream = cv.ObjectDetectionStream = function(cascade, opts){
cv.ObjectDetectionStream = function(cascade, opts){
this.classifier = new cv.CascadeClassifier(cascade); this.classifier = new cv.CascadeClassifier(cascade);
this.opts = opts || {}; this.opts = opts || {};
this.readable = true; this.readable = true;
@ -94,8 +96,7 @@ ObjectDetectionStream.prototype.write = function(m){
} }
VideoStream = VideoStream = cv.VideoStream = function(src){
cv.VideoStream = function(src){
if (!(src instanceof VideoCapture)) src = new VideoCapture(src); if (!(src instanceof VideoCapture)) src = new VideoCapture(src);
this.video = src; this.video = src;
this.readable = true; this.readable = true;
@ -134,5 +135,19 @@ VideoCapture.prototype.toStream = function(){
} }
// Provide cascade data for faces etc. // 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])
})