18

I'm trying to install openCV 2.4.2 (not the newest version but stable version compatible with newer OS X according to several sources) on Mac OS X 10.9 (Mavericks). I have tried installing from source and using homebrew but neither works. I get the following error when I try installing it:

build Marieke$ make
[ 25%] Building CXX object modules/ts/CMakeFiles/opencv_ts.dir/src/precomp.cpp.o
In file included from /users/Marieke/Downloads/OpenCV-2.4.2/modules/ts/src/precomp.cpp:1:
In file included from /users/Marieke/Downloads/OpenCV-2.4.2/modules/ts/src/precomp.hpp:2:
In file included from /users/Marieke/Downloads/OpenCV-2.4.2/modules/ts/include/opencv2/ts/ts.hpp:40:
/users/Marieke/Downloads/OpenCV-2.4.2/modules/ts/include/opencv2/ts/ts_gtest.h:1657:13: fatal error: 
      'tr1/tuple' file not found
#   include <tr1/tuple>  // NOLINT
        ^
1 error generated.
make[2]: *** [modules/ts/CMakeFiles/opencv_ts.dir/src/precomp.cpp.o] Error 1
make[1]: *** [modules/ts/CMakeFiles/opencv_ts.dir/all] Error 2
make: *** [all] Error 2

I don't know how to solve this and I have tried several things already (I do now have newest versions of Xcode, cmake, ffmpeg, faac, faad, qt, ...) so if anybody can help me, that would be much appreciated, thanks!

Marieke
  • 211
  • 1
  • 2
  • 5

7 Answers7

54

Run the following commands assuming you have brew installed.

brew tap homebrew/science
brew install opencv
zs2020
  • 53,766
  • 29
  • 154
  • 219
  • 1
    this is what i get Error: You must `brew link jpeg libpng libtiff' before opencv can be installed Rox:~ Rocela$ brew link jpeg libpng libtiff Linking /usr/local/Cellar/jpeg/8d... Error: Could not symlink include/jconfig.h /usr/local/include is not writable. – roxdurazo Jul 22 '14 at 22:44
  • 1
    @roseliux `sudo chown /usr/local/include/` this will allow your user to modify the folder and its content – Bassem Aug 02 '14 at 22:24
15

Use macports. Once you install macports, just run

sudo port install opencv

at the command prompt.

This other stackoverflow question is mostly correct for how to start using the macports version of opencv in Xcode.

Here are some more up-to-date instructions for using the macports version of OpenCV from Xcode 5:

  1. Create a new Xcode project as OS X Application -> Command Line Tool, etc.
  2. Click the target in the upper left
  3. Click the Build Settings tab
  4. Scroll down to (or search for) the Search Paths section
  5. Under User Header Search Paths add /opt/local/include
  6. Click the Build Phases tab
  7. Click Link Binary with Libraries
  8. Choose the required libraries from /opt/local/lib
    1. At least, add libopencv_core.dylib
  9. If you want pre-set command-line arguments, go to Product -> Scheme -> Edit Scheme (⌘<)
    1. Click the Run tab on the left
    2. Click the Arguments tab
    3. Enter arguments into Arguments Passed on Launch
  10. Done!
Community
  • 1
  • 1
Daniel Golden
  • 3,752
  • 2
  • 27
  • 32
12

You can try to install opencv from homebrew, I met the same problem with cmake in my 10.9 and finally I found the solution from Chris Muktar. Here are the steps:

  1. Make sure xcode-select --install Xcode command line tools 5.0.1 are installed.
  2. Install python using brew - brew install python.
  3. pip update
  4. pip install numpy
  5. brew linkapps
  6. Add export PYTHONPATH=/usr/local/Cellar/opencv/2.4.6.1/lib/python2.7/site-packages:$PYTHONPATH to .bash_profile in your home directory
  7. brew install opencv

In the last step I came across the Error: No available formula for opencv. In this case, you should first run the command brew tap homebrew/science.

Good Luck

23tux
  • 14,104
  • 15
  • 88
  • 187
GilbertLee
  • 654
  • 1
  • 6
  • 21
  • 1
    For me, OpenCV built fine, but there's no `python*` folder in the `opencv/2.4.7.1/lib` folder. Other tutorials show me that a `cv2.so` file should have been installed to one of my `site-packages` folders, but I can't find any file by that name anywhere on my system. Thus `import cv` and `import cv2` are not working in Python. – Neil Traft Mar 02 '14 at 02:31
  • @NeilTraft Sorry but I am not able to solve this problem now, wish you figure it out soon. – GilbertLee Mar 10 '14 at 17:05
  • I did figure it out. I was trying to install using a virtualenv instead of dirtying my global python installation with a version of numpy. Unfortunately the brew installation process doesn't like that. NumPy needs to be installed at the global level. Thanks. – Neil Traft Mar 11 '14 at 10:29
  • @NeilTraft, I actually have a virtualenv where I've installed numpy, scipy, and opencv from source. For OSX, there's an issue with clang, so you'll need to set this environment variable as a work around: "export ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future" – Paul Rigor Apr 30 '14 at 00:03
1

This may be related to the current issues with Qt on Mavericks.

See: https://github.com/mxcl/homebrew/pull/23793

I'd try installing the current patched homebrew keg for qt, and then installing opencv:

brew update
brew uninstall opencv
brew uninstall qt
brew install -v https://raw.github.com/cliffrowley/homebrew/patched_qt/Library/Formula/qt.rb --HEAD
brew install opencv

Caution to the wind: the qt build took me about an hour to complete

codenamev
  • 2,203
  • 18
  • 24
1

Thanks for the answers! I ended up with the following solution: I added #define GTEST_USE_OWN_TR1_TUPLE 1 to ts_gtest.h. Probably not the prettiest solution but I don't need gtest for anything else so it works for me.

Marieke
  • 211
  • 1
  • 2
  • 5
1

You could disable ts module in CMakeCache.txt file:

//Include opencv_ts module into the OpenCV build
BUILD_opencv_ts:BOOL=OFF

I mean that there is no reason to modify existing code.

aloschilov
  • 566
  • 4
  • 5
1

I think you really need to do a configuration and that is it.

I tried your problems and I think steps are as follow:

  1. open terminal in mac
  2. in the terminal, check you have cmake and ccmake. If not, please type "brew install cmake"
  3. go to your downloaded opencv folder, make a new folder by typing "mkdir build", then "cd build"
  4. in this build folder, check you have gcc and g++ installed.
  5. now, doing configuration by type "ccmake .. -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++", type "c" first for configuration then exit by "e" then "g" for generating!
  6. you should be in terminal again now! then please type "make"
  7. type "sudo make install", and now the opencv is installed, check it by type "brew list", and you should see the opencv there
  8. type "brew linkapps"
  9. do a test if you have python, by typing "import cv", and it should be working!
Euler
  • 335
  • 2
  • 5
  • 14
  • 2
    I had to install with some more params: cmake -DWITH_QUICKTIME=OFF -DWITH_GSTREAMER=OFF -DWITH_FFMPEG=OFF -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_BUILD_TYPE=Release .. ; make -j4 – Ricky Sahu Sep 05 '14 at 18:38
  • 1
    @Ricky yes, the `-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++` options are very important on OS X, because otherwise you run into syntax errors in some header files. – Kal Oct 23 '14 at 13:08