19

I have trawled through all of Google's and Stack Overflow's search results in order to install stupid OpenCV on my Mac and all the methods have been completely useless.

I started trying to do this with OS X 10.8 and its XCode version and it didn't work. Now I'm on 10.9 and XCode 5.0.1.

I have tried mainly 2 methods: 1) Downloading the .dmg file from OCV website and doing the CMAKE routine. When I get to the make -j8 step, at around 36% it gives me errors such as:

-make[1]: * [modules/imgproc/CMakeFiles/opencv_perf_imgproc.dir/all] Error 2

-Documents/Libraries/opencv-2.4.6.1/modules/ts/include/opencv2/ts/ts_perf.hpp:480:12: note: expanded from macro 'CV_PERF_TEST_MAIN_INTERNALS' while (++argc >= (--argc,-1)) {VA_ARGS; break;} /this ugly cons... ^ ~~ 1 error generated. make[2]: ** [modules/imgproc/CMakeFiles/opencv_perf_imgproc.dir/perf/perf_main.cpp.o] Error 1

2) Using Homebrew at the end of which, even if I added the python path, when I do 'import cv' it gives me a "no module named cv" error

I tried Macports as well a while ago so I don't remember the steps, but it didn't work.

It goes without saying that I've tried different versions of OCV and all have given me issues at the make step.

Any other solutions?

  • I wrote a tutorial on how to install OpenCV on a Mac (10.9 Mavericks) because I also tried a lot of different options and finally it worked like this: http://mac-opencv-projects.blogspot.fr/2014/01/installing-opencv-on-mac-os-x-1091.html – eelay Feb 03 '14 at 13:04

2 Answers2

32

There is a great tutorial located here. It highlights that the version you are trying to use "is not compatible". I am thinking that you should try installing the version stated in those instructions and see how you go.

The following instructions are taken directly from that link:

INSTALLING CMAKE

  1. First you need to download the .dmg file under Binary Distribution of CMake here. At the time of I installed this, the file name is cmake-2.8.11.2-Darwin64-universal.dmg.

  2. Upon completion of the installation you will be prompted whether to put CMake in /usr/bin, select Yes and finish installation

  3. To ensure that CMake has been successfully installed, type cmake -version in Terminal

INSTALLING OPENCV

  1. First, download the tar file of OpenCV 2.4.3 stable version here and DO NOT use the latest version. I struggled with the installation because I used OpenCV 2.4.6.1 and it's not yet compatible.

  2. Extract the tar file in a folder and go to that folder through the terminal, e.g. cd Downloads/OpenCV-2.4.3

  3. Now, each of the following line is to be executed in Terminal and must be executed successfully (no error)

    1. mkdir build
    2. cd build
    3. cmake -G "Unix Makefiles" ..
    4. make -j8
    5. sudo make install
  4. You are all set to use OpenCV!

Samuel O'Malley
  • 3,471
  • 1
  • 23
  • 41
  • That's the method I referred to in 1)...doesn't work – Rupert Cobbe-Warburton Oct 30 '13 at 00:58
  • Did you notice the part that says "DO NOT use the latest version"? I thought that might be the issue – Samuel O'Malley Oct 30 '13 at 00:59
  • What happens when you disable the performance tests? Add `-D BUILD_PERF_TESTS=OFF` when calling cmake – Samuel O'Malley Oct 30 '13 at 01:10
  • Gives me this error: Documents/Libraries/OpenCV-2.4.3/modules/highgui/src/cap_ffmpeg_impl.hpp:849:10: note: forward declaration of 'CodecID' enum CodecID codec_get_bmp_id(unsigned int tag); make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.cpp.o] Error 1 – Rupert Cobbe-Warburton Oct 30 '13 at 11:08
  • 2
    That means you need to build ffmpeg before trying to install openCV as per [this link](http://nick.txtcc.com/index.php/linux/883) – Samuel O'Malley Oct 30 '13 at 11:15
  • Now I get this error at 52%: Documents/Libraries/OpenCV-2.4.3/modules/ts/include/opencv2/ts/ts_gtest.h:1669:13: fatal error: 'tr1/tuple' file not found # include // NOLINT – Rupert Cobbe-Warburton Oct 30 '13 at 13:18
  • 2
    FINALLY, after trying so many different things, installing an older, stabler version of OpenCV did the trick – C. S. Jan 21 '14 at 20:05
  • I have tried all possible solutions for Installing openCV. This finally installed OpenCV for me. Amazing! Thanks – xrnd Apr 05 '17 at 07:28
  • Installing the CMake DMG did not give me a `cmake` command. It's no longer an installer. Instead it asks to drag and drop an app into your "applications" folder. – Schneems Mar 05 '18 at 22:21
  • Just adding, to include the contrib branch (where all the experimental features of opencv resides), use -DOPENCV_EXTRA_MODULES_PATH=/modules – Kumar Ravi Mar 22 '18 at 12:58
9

Steps for those who prefer to build opencv from source

I prefer to use cmake-gui instead of entirely doing this from command line, since that gives you more idea about the options available for opencv configuration and bring you in better position if you want to customize opencv build tomorrow ( like enabling java wrapper or OpenCL etc ).

  1. Download source either from opencv.org(1) or opencv github repo(2)
  2. Start cmake-gui.
  3. Set source path to downloaded opencv directory and build path to your choice and click Configure button. enter image description here
  4. Specify generator as unix makefiles and press Continue enter image description here
  5. Choose compilers and click Done button. enter image description here
  6. An options page with errors might be listed.

enter image description here

  1. Hovering mouse over any option gives a tooltip about the option. Edit option(s) as you feel fit. E.g.
    CMAKE_INSTALL_PREFIX - change opencv install path
    BUILD_SHARED_LIBS - build static or shared library. etc

Then click Configure again. If there are still errors, edit the option(s) causing the error and click Configure button. Repeat the edit / Configure cycle until there are no more errors. Once there are no more errors, proceed to step (8).

A minimal sample config of the WITH tab below. Feel free to play with options. This might cause build problems initially. But your understanding of build, will be better. enter image description here

  1. Click Generate to generate make files.
  2. Type make ( in terminal at build folder )
  3. Type make install
kiranpradeep
  • 10,859
  • 4
  • 50
  • 82