Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example - Using with Node #97

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -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;

31 changes: 31 additions & 0 deletions bin/tracking.js
Original file line number Diff line number Diff line change
@@ -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);
});

Binary file added examples/assets/faces-found.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions test/utils/sandbox.js → index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
"type": "git",
"url": "[email protected]: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",
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion test/Brief.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var tracking = require('./utils/sandbox.js');
var tracking = require('../index');

module.exports = {
setUp: function(done) {
Expand Down
2 changes: 1 addition & 1 deletion test/ColorTracker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var tracking = require('./utils/sandbox.js');
var tracking = require('../index');

module.exports = {
setUp: function(done) {
Expand Down
2 changes: 1 addition & 1 deletion test/Fast.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var tracking = require('./utils/sandbox.js');
var tracking = require('../index');

module.exports = {
setUp: function(done) {
Expand Down
2 changes: 1 addition & 1 deletion test/ObjectTracker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var tracking = require('./utils/sandbox.js');
var tracking = require('../index');

module.exports = {
setUp: function(done) {
Expand Down
2 changes: 1 addition & 1 deletion test/perf/Brief.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var PNG = require('png-js');
var tracking = require('../utils/sandbox.js');
var tracking = require('../../index');

var corners1;
var corners2;
Expand Down
2 changes: 1 addition & 1 deletion test/perf/ColorTracker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var PNG = require('png-js');
var tracking = require('../utils/sandbox.js');
var tracking = require('../../index');

var image;
var imageHeight = 550;
Expand Down
2 changes: 1 addition & 1 deletion test/perf/Fast.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var PNG = require('png-js');
var tracking = require('../utils/sandbox.js');
var tracking = require('../../index');

var image;
var imageGray;
Expand Down
2 changes: 1 addition & 1 deletion test/perf/ObjectTracker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var PNG = require('png-js');
var tracking = require('../utils/sandbox.js');
var tracking = require('../../index');

var image;
var imageHeight = 600;
Expand Down