diff --git a/bin/cli.js b/bin/cli.js new file mode 100644 index 0000000..f02ad20 --- /dev/null +++ b/bin/cli.js @@ -0,0 +1,33 @@ +"use strict"; + +module.exports = require("yargs") + .usage("Usage: ./tracking.js -f FILENAMES -c CLASSIFIERS [-d DIRECTORY]") + .alias("h", "help") + .option('c', { + alias: "classifiers", + array: true, + demand: true, + describe: "haarcascade classifier filename", + type: "string" + }) + .option('f', { + alias: "filenames", + array: true, + describe: "one (or several) input filename(s)", + type: "string" + }) + .option('d', { + alias: "directory", + describe: "directory containing classifiers and images", + type: "string" + }) + .example("$ ./tracking.js -f myface.png -c faces.xml") + .example("$ ./tracking.js -d photos/summer_photos/ -c smiles.xml faces.xml") + .check(function (a) { + if (!((a.f || a.d) && !(a.f && a.d))) + throw new Error('Error:\n\tFilename or Directory must be set. Not both.'); + + return true; + }) + .argv; + diff --git a/bin/tracking.js b/bin/tracking.js new file mode 100755 index 0000000..15500b7 --- /dev/null +++ b/bin/tracking.js @@ -0,0 +1,31 @@ +#!/usr/bin/env node +'use strict'; + +const Canvas = require('canvas'); +const Image = Canvas.Image; +const fs = require('fs'); +const path = require('path') +const tracking = require('../index'); +const argv = require('./cli'); + +var img = new Image(); +var canvas = new Canvas(200, 200); +var ctx = canvas.getContext('2d'); +var tracker = new tracking.ObjectTracker(['face']); + +tracker.setStepSize(1.7); +tracker.on('track', function (evt) { + evt.data.forEach(function (rect) { + console.log(rect); + }); +}); + +argv.filenames.map(function (fname) { + img.src = fs.readFileSync(fname); + canvas.width = img.width; + canvas.height = img.height; + ctx.drawImage(img, 0, 0); + + tracking.trackCanvas_(canvas, tracker); +}); + diff --git a/examples/assets/faces-found.png b/examples/assets/faces-found.png new file mode 100644 index 0000000..dc48f20 Binary files /dev/null and b/examples/assets/faces-found.png differ diff --git a/test/utils/sandbox.js b/index.js similarity index 58% rename from test/utils/sandbox.js rename to index.js index 7f5b039..e52eb2e 100644 --- a/test/utils/sandbox.js +++ b/index.js @@ -1,8 +1,11 @@ -'use strict'; - +var buildDir = require('path').resolve(__dirname, './build/'); var nodeunit = require('nodeunit'); -var context = nodeunit.utils.sandbox(['build/tracking.js', 'build/data/eye.js', 'build/data/face.js', 'build/data/mouth.js'], { +var context = nodeunit.utils.sandbox([ + buildDir + '/tracking.js', + buildDir + '/data/eye.js', + buildDir + '/data/face.js', + buildDir + '/data/mouth.js'], { Float32Array: Float32Array, Float64Array: Float64Array, Int16Array: Int16Array, diff --git a/package.json b/package.json index debffef..c79d6c6 100644 --- a/package.json +++ b/package.json @@ -18,11 +18,13 @@ "type": "git", "url": "git@github.com:eduardolundgren/tracking.js.git" }, + "main": "index.js", "scripts": { "test": "gulp test" }, "license": "BSD", "devDependencies": { + "canvas": "^1.2.3", "gulp": "^3.8.1", "gulp-concat": "^2.2.0", "gulp-esformatter": "^0.5.0", @@ -36,6 +38,7 @@ "jshint-stylish": "^0.4.0", "nodeunit": "0.9.0", "png-js": "0.1.1", - "run-sequence": "^0.3.6" + "run-sequence": "^0.3.6", + "yargs": "^3.14.0" } } diff --git a/test/Brief.js b/test/Brief.js index 15265fc..51f532a 100644 --- a/test/Brief.js +++ b/test/Brief.js @@ -1,6 +1,6 @@ 'use strict'; -var tracking = require('./utils/sandbox.js'); +var tracking = require('../index'); module.exports = { setUp: function(done) { diff --git a/test/ColorTracker.js b/test/ColorTracker.js index 1daacca..4d8529f 100644 --- a/test/ColorTracker.js +++ b/test/ColorTracker.js @@ -1,6 +1,6 @@ 'use strict'; -var tracking = require('./utils/sandbox.js'); +var tracking = require('../index'); module.exports = { setUp: function(done) { diff --git a/test/Fast.js b/test/Fast.js index 103658b..9993152 100644 --- a/test/Fast.js +++ b/test/Fast.js @@ -1,6 +1,6 @@ 'use strict'; -var tracking = require('./utils/sandbox.js'); +var tracking = require('../index'); module.exports = { setUp: function(done) { diff --git a/test/ObjectTracker.js b/test/ObjectTracker.js index be99797..7425c7b 100644 --- a/test/ObjectTracker.js +++ b/test/ObjectTracker.js @@ -1,6 +1,6 @@ 'use strict'; -var tracking = require('./utils/sandbox.js'); +var tracking = require('../index'); module.exports = { setUp: function(done) { diff --git a/test/perf/Brief.js b/test/perf/Brief.js index 4a0662a..1def32f 100644 --- a/test/perf/Brief.js +++ b/test/perf/Brief.js @@ -1,5 +1,5 @@ var PNG = require('png-js'); -var tracking = require('../utils/sandbox.js'); +var tracking = require('../../index'); var corners1; var corners2; diff --git a/test/perf/ColorTracker.js b/test/perf/ColorTracker.js index d6ae296..e7c68fe 100644 --- a/test/perf/ColorTracker.js +++ b/test/perf/ColorTracker.js @@ -1,5 +1,5 @@ var PNG = require('png-js'); -var tracking = require('../utils/sandbox.js'); +var tracking = require('../../index'); var image; var imageHeight = 550; diff --git a/test/perf/Fast.js b/test/perf/Fast.js index dc857a7..e2dd2f1 100644 --- a/test/perf/Fast.js +++ b/test/perf/Fast.js @@ -1,5 +1,5 @@ var PNG = require('png-js'); -var tracking = require('../utils/sandbox.js'); +var tracking = require('../../index'); var image; var imageGray; diff --git a/test/perf/ObjectTracker.js b/test/perf/ObjectTracker.js index 2125d88..02e7bb8 100644 --- a/test/perf/ObjectTracker.js +++ b/test/perf/ObjectTracker.js @@ -1,5 +1,5 @@ var PNG = require('png-js'); -var tracking = require('../utils/sandbox.js'); +var tracking = require('../../index'); var image; var imageHeight = 600;