OpenCV3 installation on Mac

775 views Asked by At

I tried to install OpenCV3 for Mac with the following command in terminal:

brew install opencv3 --with-contrib -with-ffmpeg

It repeatedly gets stuck at this point:

cmake .. -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -DCMAKE

Can someone please tell me how to fix this?

2

There are 2 answers

0
Mark Setchell On

You need to install Xcode command line tools first. Go to the AppStore and download and install Xcode from Apple for free.

Then run:

xcode-select --install

to get make,cmake, and all the command-line development tools.


Also, consider adding the QuickTime back-end, by additionally specifying --with-qt5, i.e.:

brew install opencv3 --with-contrib -with-ffmpeg --with-qt5

That gives you extra options to save the images you generate and display with the highgui module.

0
Pacific Stickler On

I also had the exact same issue. Someone else had also reported this problem on the brew github, but they could also not reproduce the issue. In my case though, it would go a step further and get stuck after calling make for hours:

cmake .. -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -DCMAKE
make

I went ahead and tracked the processes in the Activity Monitor on my Mac and found out that it kicks off a batch of clang processes in sequence on multiple threads. But I had several apps running that were robbing it of CPU and Memory resources. So I shut down Safari, Finder, IDEs (XCode, PyCharm) etc, and this time it did complete.

Solution: was to just let it run with as much CPU and memory overhead it needs. And with no other power-hungry apps running in the background, it finished in 25mins.

CMake Approach: Your next best approach is to bypass using package manager, like brew, and follow the instructions given on PyImageSearch to build OpenCV manually using CMake:

  1. Install dependencies like CMake, pkg-config (and possibly others...)
  2. Clone OpenCV and OpenCV_Contrib git repos:
    1. https://github.com/opencv/opencv
    2. https://github.com/opencv/opencv_contrib
  3. Checkout version [e.g. 3.2.0]
  4. Make build directory inside opencv directory
  5. Run CMake with the appropriate parameters for your system:

    cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3 \ -D PYTHON2_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages \ -D PYTHON2_LIBRARY=/usr/local/opt/python/bin \ -D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers \ -D BUILD_OPENCV_PYTHON2=ON \ -D INSTALL_C_EXAMPLES=OFF \ -D INSTALL_PYTHON_EXAMPLES=OFF \ -D BUILD_EXAMPLES=OFF \ -D OPENCV_EXTRA_MODULES_PATH=/Users/Salman_Naqvi/Downloads/opencv_contrib/modules ..

  6. Compile using: make -j4

  7. Install it on MacOS: make install

--> It'll be installed in the directory specified by: CMAKE_INSTALL_PREFIX=/usr/local/opencv3