This repository has been archived by the owner on Jul 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommandline.js
74 lines (60 loc) · 1.92 KB
/
commandline.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env node
var usage =
"[USAGE]\n" +
" node commandline.js [options] expect_path target_path\n" +
"\n" +
"ex)\n" +
" $ node commandline.js -threshold 1.0 -span 10 test/images test/images2\n";
var supportedOptions = [
'threshold',
'span',
'pyrScale',
'pyrLevels',
'winSize',
'pyrIterations',
'polyN',
'polySigma',
'flags',
];
function suppressCout() {
var util = require('util');
var fs = require('fs');
var dup2 = require('node-dup2');
var stdout = fs.openSync("/dev/null", "a"); // dummy
dup2.invoke(1, stdout);
var devNull = fs.openSync("/dev/null", "a");
dup2.invoke(devNull, 1);
function printToStdout(s) {
fs.write(stdout, JSON.stringify(s, null, ' ') + "\n");
}
console.__defineGetter__('log', function(){ return printToStdout; });
console.__defineGetter__('error', function(){ return printToStdout; });
console.__defineGetter__('info', function(){ return printToStdout; });
}
function getArgs() {
var minimist = require('minimist');
var args = minimist(process.argv.slice(2));
var expect_path = args._[0];
var target_path = args._[1];
var options = {};
supportedOptions.forEach(function(s){ options[s] = args[s] });
if (!expect_path || !target_path) {
console.error(usage);
process.exit(-1);
}
return {
expect_path: expect_path,
target_path: target_path,
options: options };
}
function main(expect_path, target_path, options) {
var OpticalFlow = require('./opticalflow.js');
suppressCout(); // suppress log messages using cout in OpticalFlow C++ module
var opticalflow = new OpticalFlow();
opticalflow.on('message', function(msg) { console.log(msg); });
opticalflow.on('error', function(err) { console.error(err); });
opticalflow.once('finish', function finish(report) { console.info(report); });
opticalflow.calc(expect_path, target_path, options);
}
var args = getArgs();
main(args.expect_path, args.target_path, args.options);