Last active
August 12, 2019 11:38
-
-
Save agathauy/a928315a7102b0f2789f684cb265d6ee to your computer and use it in GitHub Desktop.
OpenCV cmake script. Tested on 3.4.5 and 4.0.0 on Mac OS #opencv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reference https://www.learnopencv.com/install-opencv-4-on-macos/ | |
# compiled scripts, modified to get it working for custom python path | |
brew install python3 | |
brew install cmake | |
brew install qt5 | |
QT5PATH=/usr/local/Cellar/qt/5.11.2_1 | |
cwd=$(pwd) | |
cvVersion="3.4.4" | |
# Clean build directories | |
rm -rf opencv/build | |
rm -rf opencv_contrib/build | |
# Create directory for installation | |
mkdir installation | |
mkdir installation/OpenCV-"$cvVersion" | |
sudo -H pip3 install -U pip numpy | |
# Install virtual environment | |
sudo -H python3 -m pip install virtualenv virtualenvwrapper | |
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3 | |
echo "VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3" >> ~/.bash_profile | |
echo "# Virtual Environment Wrapper" >> ~/.bash_profile | |
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bash_profile | |
cd $cwd | |
source /usr/local/bin/virtualenvwrapper.sh | |
############ For Python 3 ############ | |
# create virtual environment | |
mkvirtualenv OpenCV-"$cvVersion"-py3 -p python3 | |
workon OpenCV-"$cvVersion"-py3 | |
# now install python libraries within this virtual environment | |
pip install cmake numpy scipy matplotlib scikit-image scikit-learn ipython dlib | |
cmake -D CMAKE_BUILD_TYPE=RELEASE \ | |
-D CMAKE_INSTALL_PREFIX=$cwd/installation/OpenCV-3.4.5 \ | |
-D INSTALL_C_EXAMPLES=ON \ | |
-D INSTALL_PYTHON_EXAMPLES=ON \ | |
-D WITH_TBB=ON \ | |
-D WITH_V4L=ON \ | |
-D OPENCV_SKIP_PYTHON_LOADER=ON \ | |
-D CMAKE_PREFIX_PATH=$QT5PATH \ | |
-D CMAKE_MODULE_PATH="$QT5PATH"/lib/cmake \ | |
-D OPENCV_PYTHON3_INSTALL_PATH=/miniconda3/envs/cv34/lib/python3.6/site-packages \ | |
-D PYTHON3_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \ | |
-D PYTHON3_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") \ | |
-D PYTHON3_EXECUTABLE:FILEPATH=`which python` \ | |
-D WITH_QT=ON \ | |
-D WITH_OPENGL=ON \ | |
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.5/modules \ | |
-D BUILD_EXAMPLES=ON .. | |
make -j$(sysctl -n hw.physicalcpu) | |
make install | |
cd $cwd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment