Here are the steps to compile and install the source code to try out the latest version of OpenCV on your Mac. Although it says El Capitan, it seems that it will work with other versions because we have confirmed the operation with El Capitan.
First of all, please install Xcode as a preparation.
Download and install the dmg file from the following site.
https://cmake.org/download/
By the way, the file I downloaded was "cmake-3.6.2-Darwin-x86_64.dmg".
Execute the following command so that CMake installed by GUI can be used on the command line.
python
$ sudo ln -s "/Applications/CMake.app/Contents/bin/ccmake" /usr/local/bin/ccmake
$ sudo ln -s "/Applications/CMake.app/Contents/bin/cmake" /usr/local/bin/cmake
$ sudo ln -s "/Applications/CMake.app/Contents/bin/cmake-gui" /usr/local/bin/cmake-gui
$ sudo ln -s "/Applications/CMake.app/Contents/bin/cmakexbuild" /usr/local/bin/cmakexbuild
$ sudo ln -s "/Applications/CMake.app/Contents/bin/cpack" /usr/local/bin/cpack
$ sudo ln -s "/Applications/CMake.app/Contents/bin/ctest" /usr/local/bin/ctest
Download the latest version from GitHub. By the way, opencv_contrib is an additional library, but it makes little sense without it, so please think it is essential (^ _ ^;)
python
$ cd ~
$ git clone https://github.com/Itseez/opencv.git
$ git clone https://github.com/Itseez/opencv_contrib.git
Compile and install with the following command.
python
$ cd opencv
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D PYTHON3_EXECUTABLE=/Users/[username]/.pyenv/versions/anaconda3-4.1.1/bin/python \
-D PYTHON3_INCLUDE_DIR=/Users/[username]/.pyenv/versions/anaconda3-4.1.1/include/python3.5m \
-D PYTHON3_LIBRARY=/Users/[username]/.pyenv/versions/anaconda3-4.1.1/lib/libpython3.5m.dylib \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/Users/[username]/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages/numpy/core/include \
-D PYTHON3_PACKAGES_PATH=/Users/[username]/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D BUILD_opencv_python3=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
..
$ make -j4
$ sudo make install
By the way, Python3 was installed by following the steps on the following page. The above command is for Anaconda version 3-4.1.1, so if the version is different, edit it according to the version you are using. In addition, the part marked [username] also needs to be edited according to the environment of the Mac on which it is installed.
http://qiita.com/mix_dvd/items/d915752215db67919c06
When I try to run the sample code from Python, I get an error saying that the library fails to load, so I borrow a compiled library from another program and use it.
python
$ cd ~/
$ git clone https://github.com/open-ephys-GUI-binaries/osx-yosemite.git
$ sudo cp osx-yosemite/libhdf5* /usr/local/lib
[error indication]
python
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/[username]/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages/cv2.cpython-35m-darwin.so, 2): Library not loaded: libhdf5_cpp.11.dylib
Referenced from: /usr/local/lib/libopencv_hdf.3.1.dylib
Reason: image not found
>>>
Run the following shell script and the installation should be complete ... Please change the user name and the version of each application as appropriate.
install_opencv.sh
#CMake installation
curl -OL https://cmake.org/files/v3.7/cmake-3.7.0-rc1-Darwin-x86_64.dmg
hdiutil mount ./cmake-3.7.0-rc1-Darwin-x86_64.dmg
sudo cp -r /Volumes/cmake-3.7.0-rc1-Darwin-x86_64/CMake.app /Applications
umount /Volumes/cmake-3.7.0-rc1-Darwin-x86_64
#CMake settings
sudo ln -s "/Applications/CMake.app/Contents/bin/ccmake" /usr/local/bin/ccmake
sudo ln -s "/Applications/CMake.app/Contents/bin/cmake" /usr/local/bin/cmake
sudo ln -s "/Applications/CMake.app/Contents/bin/cmake-gui" /usr/local/bin/cmake-gui
sudo ln -s "/Applications/CMake.app/Contents/bin/cmakexbuild" /usr/local/bin/cmakexbuild
sudo ln -s "/Applications/CMake.app/Contents/bin/cpack" /usr/local/bin/cpack
sudo ln -s "/Applications/CMake.app/Contents/bin/ctest" /usr/local/bin/ctest
#OpenCV download
cd ~
git clone https://github.com/Itseez/opencv.git
git clone https://github.com/Itseez/opencv_contrib.git
#OpenCV installation
cd opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D PYTHON3_EXECUTABLE=/Users/[username]/.pyenv/versions/anaconda3-4.1.1/bin/python \
-D PYTHON3_INCLUDE_DIR=/Users/[username]/.pyenv/versions/anaconda3-4.1.1/include/python3.5m \
-D PYTHON3_LIBRARY=/Users/[username]/.pyenv/versions/anaconda3-4.1.1/lib/libpython3.5m.dylib \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/Users/[username]/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages/numpy/core/include \
-D PYTHON3_PACKAGES_PATH=/Users/[username]/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D BUILD_opencv_python3=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
..
make -j4
sudo make install
#Install additional libraries
git clone https://github.com/open-ephys-GUI-binaries/osx-yosemite.git
sudo cp osx-yosemite/libhdf5* /usr/local/lib
Recommended Posts