gyp errors when trying to install opencv node on mac mavericks trouble

1.2k views Asked by At

I am trying to install node opencv , i'm running mavericks on a mac. i run "npm install opencv" and have tried so many things to fix this problem but can't figure it out. here are my errors: there are also a bunch of warnings but this is the errors before it fails:

similar errors happen when i run node-gyp configure or node-gyp rebuild I tried to get help here: https://github.com/joyent/node/issues/3113 but it didn't help, I still get gyp errors

when running npm install opencv: here is the entire output

npm WARN package.json [email protected] No repository field.
npm http GET https://registry.npmjs.org/opencv
npm http 304 https://registry.npmjs.org/opencv

> [email protected] preinstall /Users/gabriellalevine/ardrone-webflight/node_modules/opencv
> node-gyp clean rebuild

  CXX(target) Release/obj.target/opencv/src/init.o
  CXX(target) Release/obj.target/opencv/src/Matrix.o
../src/Matrix.cc:110:13: warning: variable 'mat' is used uninitialized whenever
      'if' condition is false [-Wsometimes-uninitialized]
        } else if (args.Length() == 5) {
                   ^~~~~~~~~~~~~~~~~~
../src/Matrix.cc:119:2: note: uninitialized use occurs here
        mat->Wrap(args.Holder());
        ^~~
../src/Matrix.cc:110:9: note: remove the 'if' if its condition is always true
        } else if (args.Length() == 5) {
               ^~~~~~~~~~~~~~~~~~~~~~~~
../src/Matrix.cc:104:13: note: initialize the variable 'mat' to silence this
      warning
        Matrix *mat;
                   ^
                    = nullptr
1 warning generated.
  CXX(target) Release/obj.target/opencv/src/OpenCV.o
  CXX(target) Release/obj.target/opencv/src/CascadeClassifierWrap.o
  CXX(target) Release/obj.target/opencv/src/Contours.o
  CXX(target) Release/obj.target/opencv/src/Point.o
  CXX(target) Release/obj.target/opencv/src/VideoCaptureWrap.o
  CXX(target) Release/obj.target/opencv/src/CamShift.o
  CXX(target) Release/obj.target/opencv/src/HighGUI.o
../src/HighGUI.cc:38:13: warning: variable 'win' is used uninitialized whenever
      'if' condition is false [-Wsometimes-uninitialized]
        } else if (args.Length() == 2){
                   ^~~~~~~~~~~~~~~~~~
../src/HighGUI.cc:42:2: note: uninitialized use occurs here
        win->Wrap(args.Holder());
        ^~~
../src/HighGUI.cc:38:9: note: remove the 'if' if its condition is always true
        } else if (args.Length() == 2){
               ^~~~~~~~~~~~~~~~~~~~~~~
../src/HighGUI.cc:35:19: note: initialize the variable 'win' to silence this
      warning
  NamedWindow* win;
                  ^
                   = nullptr
1 warning generated.
  CXX(target) Release/obj.target/opencv/src/FaceRecognizer.o
../src/FaceRecognizer.cc:64:76: error: too many arguments to function call,
      expected at most 4, have 5
  ...f = cv::createLBPHFaceRecognizer(1, 8, 8, 8, 80.0);
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~             ^~~~
/usr/local/Cellar/opencv/2.4.0/include/opencv2/contrib/contrib.hpp:951:16: note: 
      'createLBPHFaceRecognizer' declared here
    CV_EXPORTS Ptr<FaceRecognizer> createLBPHFaceRecognizer(int radius=1...
               ^
../src/FaceRecognizer.cc:90:42: error: too many arguments to function call,
      expected at most 4, have 5
      radius, neighbors, grid_x, grid_y, threshold
                                         ^~~~~~~~~
/usr/local/Cellar/opencv/2.4.0/include/opencv2/contrib/contrib.hpp:951:16: note: 
      'createLBPHFaceRecognizer' declared here
    CV_EXPORTS Ptr<FaceRecognizer> createLBPHFaceRecognizer(int radius=1...
               ^
../src/FaceRecognizer.cc:111:19: error: too many arguments to function call,
      expected at most single argument 'num_components', have 2 arguments
      components, threshold
                  ^~~~~~~~~
/usr/local/Cellar/opencv/2.4.0/include/opencv2/contrib/contrib.hpp:949:16: note: 
      'createEigenFaceRecognizer' declared here
    CV_EXPORTS Ptr<FaceRecognizer> createEigenFaceRecognizer(int num_com...
               ^
../src/FaceRecognizer.cc:132:19: error: too many arguments to function call,
      expected at most single argument 'num_components', have 2 arguments
      components, threshold
                  ^~~~~~~~~
/usr/local/Cellar/opencv/2.4.0/include/opencv2/contrib/contrib.hpp:950:16: note: 
      'createFisherFaceRecognizer' declared here
    CV_EXPORTS Ptr<FaceRecognizer> createFisherFaceRecognizer(int num_co...
               ^
../src/FaceRecognizer.cc:218:14: error: no member named 'update' in
      'cv::FaceRecognizer'
  self->rec->update(images, labels);
  ~~~~~~~~~  ^
../src/FaceRecognizer.cc:234:26: error: too many arguments to function call,
      expected single argument 'src', have 3 arguments
  self->rec->predict(im, predictedLabel, confidence);
  ~~~~~~~~~~~~~~~~~~     ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/opencv/2.4.0/include/opencv2/contrib/contrib.hpp:931:9: note: 
      'predict' declared here
        virtual int predict(InputArray src) const = 0;
        ^
../src/FaceRecognizer.cc:273:26: error: no member named 'getMat' in
      'cv::FaceRecognizer'
  cv::Mat m = self->rec->getMat(key);
              ~~~~~~~~~  ^
7 errors generated.
make: *** [Release/obj.target/opencv/src/FaceRecognizer.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Darwin 13.0.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "clean" "rebuild"
gyp ERR! cwd /Users/gabriellalevine/ardrone-webflight/node_modules/opencv
gyp ERR! node -v v0.10.20
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok 
npm ERR! weird error 1
npm ERR! not ok code 0
2

There are 2 answers

9
loganfsmyth On

Your errors are things like this:

../src/FaceRecognizer.cc:64:76: error: too many arguments to function call,
      expected at most 4, have 5
  ...f = cv::createLBPHFaceRecognizer(1, 8, 8, 8, 80.0);

So the OpenCV version you are compiling against is different from the one that the node module works with.

The fifth argument to createLBPHFaceRecognizer was added in this opencv commit, so it looks like you will need at least OpenCV v2.4.3, whereas you errors mention v2.4.0.

You should make sure your brew install is full up-to-date by running brew update and then brew upgrade opencv to pull in the most recent OpenCV from homebrew, which looks to be v2.4.7.1.

0
Erik Ušaj On

Hm, in my case was not the same, but you can try the following. Here is how I fixed OpenCV and npm opencv on Mac OS X:

  1. install homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  2. install opencv brew install homebrew/science/opencv

  3. install pkg-config: brew install pkg-config

  4. Find location of file named opencv.pc by running mdfind -name opencv.pc

  5. Run nano .bash_profile and add path found in step 4. to your Bash environment variables. Save file. Close and relaunch Terminal.

Example from my Mac:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/Cellar/opencv/2.4.12_2/lib/pkgconfig
export PKG_CONFIG_PATH

You can check if configured by running env | grep PKG_CONFIG_PATH in your terminal.