Install OpenCV 3.0 and Python 2.7+ on OSX
I’ve recently wanted to play a bit with OpenCV on my OSX machine.
In order to do that, I used Adrian Rosebrock’s excellent site: Install OpenCV 3.0 and Python 2.7+ on OSX
However, I had some issues during the installation, mainly because the CMake options were changed recently. This tutorial is mainly about how I tracked these changes and handled them. Other than that, I recommend using Adrian’s tutorial as it covers everything you need to do in order to install OpenCV 3.0 and Python 2.7+ on OSX.
As described in the blog post, you need to perform the following steps:
- Install Xcode
- Install Homebrew
- Install python 2.7
- Create virtualenv
- Install numpy
- Install CMake
- Clone opencv github repository and opencv_contrib
- Run CMake, compile and install
On step 8 (Run CMake, compile and install) I ran into some troubles. For some reasons, on the CMake results, opencv didn’t include python2 as one of its modules. I’ve verified the CMake parameters but ended up with the same results after running it again.
If you look in the opencv root folder, you will find a file called “CMakeLists.txt”. This file is the input to the CMake build system and it includes all the steps and used parameters in the build.
In the file, I’ve found the following part:
It seems that CMake step was changed recently and now it uses the following parameters:
- BUILD_opencv_python2 - Boolean stating if we building with python2
- PYTHON2_LIBRARIES - Path to our Hombrew installation of Python.
- PYTHON2_NUMPY_INCLUDE_DIRS - Directory of numpy include files.
And so I ended up with the following command:
One last note, if you get the following error while running “make -j4”:
It means that you didn’t set the PYTHON2_NUMPY_INCLUDE_DIRS parameter correctly, and you need to point it to the correct location. The CMake step won’t fail but the build step will.
Bottom line, in the future the CMake step will probably change some more, in that case, you can just check CMakeLists.txt and use the required parameters as they are being used in the file.