fisheye-correction-plus
Version:
A opencv fisheye camera model bindings for Node.js
72 lines (61 loc) • 1.9 kB
JavaScript
;
const exec = require("child_process").exec;
const fs = require("fs");
const flag = process.argv[2] || "--exists";
const opencv = "opencv";
function main() {
//Try using pkg-config, but if it fails and it is on Windows, try the fallback
exec("pkg-config " + opencv + " " + flag, function(error, stdout, stderr) {
if (error) {
if (process.platform === "win32") {
fallback();
} else {
throw new Error("ERROR: failed to run: pkg-config", opencv, flag);
}
} else {
console.log(stdout);
}
});
}
//======================Windows Specific=======================================
function fallback() {
exec("echo %OPENCV_DIR%", function(error, stdout, stderr) {
stdout = cleanupEchoOutput(stdout);
if (error) {
throw new Error("ERROR: There was an error reading OPENCV_DIR");
} else if (stdout === "%OPENCV_DIR%") {
throw new Error("ERROR: OPENCV_DIR doesn't seem to be defined");
} else {
printPaths(stdout);
}
});
}
function printPaths(opencvPath) {
if (flag === "--cflags") {
console.log('"' + opencvPath + '\\..\\..\\include"');
console.log('"' + opencvPath + '\\..\\..\\include\\opencv"');
} else if (flag === "--libs") {
var libPath = opencvPath + "\\lib\\";
fs.readdir(libPath, function(err, files) {
if (err) {
throw new Error("ERROR: couldn't read the lib directory " + err);
}
var libs = "";
for (var i = 0; i < files.length; i++) {
if (getExtension(files[i]) === "lib") {
libs = libs + ' "' + libPath + files[i] + '" \r\n ';
}
}
console.log(libs);
});
} else {
throw new Error("Error: unknown argument '" + flag + "'");
}
}
function cleanupEchoOutput(s) {
return s.slice(0, s.length - 2);
}
function getExtension(s) {
return s.substr(s.lastIndexOf(".") + 1);
}
main();