mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Make the use of OPENCV_DIR on Windows match that of the OpenCV docs
This commit is contained in:
parent
9fd5d28f6a
commit
56f27f9e23
12
README.md
12
README.md
@ -16,16 +16,18 @@ cool, I'd love to hear about it!
|
||||
You'll need OpenCV 2.3.1 or newer installed before installing node-opencv.
|
||||
|
||||
## Specific for Windows
|
||||
1. Download and install opencv (Be sure to use a 2.4 version) @
|
||||
1. Download and install OpenCV (Be sure to use a 2.4 version) @
|
||||
http://opencv.org/downloads.html
|
||||
For these instructions we will assume OpenCV is put at C:\OpenCV, but you can
|
||||
adjust accordingly.
|
||||
|
||||
2. Add the following to your PATH variable
|
||||
C:\OpenCV\build\x64\vc12\bin;
|
||||
The "x64" needs to match the version of NodeJS you are using.
|
||||
2. If you haven't already, create a system variable called OPENCV_DIR and set it
|
||||
to C:\OpenCV\build\x64\vc12
|
||||
|
||||
Also set OPENCV_DIR to C:\OpenCV\build
|
||||
Make sure the "x64" part matches the version of NodeJS you are using.
|
||||
|
||||
Also add the following to your system PATH
|
||||
;%OPENCV_DIR%\bin
|
||||
|
||||
3. Install Visual Studio 2013. Make sure to get the C++ components.
|
||||
You can use a different edition, just make sure OpenCV supports it, and you
|
||||
|
||||
@ -3,13 +3,15 @@ var fs = require("fs");
|
||||
var flag = process.argv[2];
|
||||
|
||||
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: pkg-config couldn't find OpenCV");
|
||||
}
|
||||
}
|
||||
else{
|
||||
console.log(stdout);
|
||||
@ -23,33 +25,28 @@ function fallback(){
|
||||
exec("echo %OPENCV_DIR%", function(error, stdout, stderr){
|
||||
stdout = cleanupEchoOutput(stdout);
|
||||
if(error){
|
||||
console.log("ERROR: There was an error reading OPENCV_DIR");
|
||||
throw new Error("ERROR: There was an error reading OPENCV_DIR");
|
||||
}
|
||||
else if(stdout === "%OPENCV_DIR%") {
|
||||
console.log("ERROR: OPENCV_DIR doesn't seem to be defined");
|
||||
throw new Error("ERROR: OPENCV_DIR doesn't seem to be defined");
|
||||
}
|
||||
else {
|
||||
getVisualStudioVersion(function(version){
|
||||
getProcessArch(function(bits){
|
||||
printPaths(stdout, version, bits);
|
||||
});
|
||||
});
|
||||
printPaths(stdout);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function printPaths(opencvPath, version, bits){
|
||||
function printPaths(opencvPath){
|
||||
if(flag === "--cflags") {
|
||||
console.log("\"" + opencvPath + "include\"");
|
||||
console.log("\"" + opencvPath + "include\\opencv\"");
|
||||
console.log("\"" + opencvPath + "\\..\\..\\include\"");
|
||||
console.log("\"" + opencvPath + "\\..\\..\\include\\opencv\"");
|
||||
}
|
||||
else if(flag === "--libs") {
|
||||
var libPath = opencvPath + bits + "\\vc" + version + "\\lib\\";
|
||||
var libPath = opencvPath + "\\lib\\";
|
||||
|
||||
fs.readdir(libPath, function(err, files){
|
||||
if(err){
|
||||
console.log("ERROR: couldn't read the lib directory");
|
||||
console.log(err);
|
||||
throw new Error("ERROR: couldn't read the lib directory " + err);
|
||||
}
|
||||
|
||||
var libs = "";
|
||||
@ -62,49 +59,10 @@ function printPaths(opencvPath, version, bits){
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.log("Error: unknown argument '" + flag + "'");
|
||||
throw new Error("Error: unknown argument '" + flag + "'");
|
||||
}
|
||||
}
|
||||
|
||||
//This gets the architecture of the NodeJS that is running this script,
|
||||
//either x86 or x64
|
||||
function getProcessArch(cb){
|
||||
exec("echo %PROCESSOR_ARCHITECTURE%", function(error, stdout, stderr) {
|
||||
if(!error) {
|
||||
var arch = cleanupEchoOutput(stdout);
|
||||
if(arch === "AMD64"){
|
||||
cb("x64");
|
||||
}
|
||||
else if(arch === "x86"){
|
||||
cb("x86");
|
||||
}
|
||||
else {
|
||||
console.log("ERROR: Unrecognized architecture");
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log("ERROR: There was an error getting the architecture");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getVisualStudioVersion(cb, version){
|
||||
if(typeof(version) === "undefined") version = 11;
|
||||
exec("reg query HKEY_CLASSES_ROOT\\VisualStudio.DTE." + version + ".0",
|
||||
function(error, stdout, stderr){
|
||||
if(!error){
|
||||
cb(version);
|
||||
}
|
||||
else if(version < 13) {
|
||||
//Try the next version
|
||||
getVisualStudioVersion(cb, version + 1);
|
||||
}
|
||||
else {
|
||||
console.log("ERROR: Can't find Visual Studio");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function cleanupEchoOutput(s){
|
||||
return s.slice(0, s.length - 2);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user