Last active
June 19, 2019 18:51
-
-
Save kylehounslow/7e4ba56cc7f6191a7ea373fef463589a to your computer and use it in GitHub Desktop.
Script to install OpenCV 4.1 + contrib modules with Python3.5 bindings on Ubuntu.
This file contains hidden or 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
# run with `sudo ./install_opencv41_py35_linux.sh` | |
OPENCV_VERSION=4.1.0 | |
apt-get install -y build-essential | |
apt-get install -y cmake | |
apt-get install -y wget | |
apt-get install -y git | |
apt-get install -y unzip | |
apt-get install -y yasm | |
apt-get install -y pkg-config | |
apt-get install -y libjpeg-dev | |
apt-get install -y libtiff-dev | |
apt-get install -y libpng-dev | |
apt-get install -y libavcodec-dev | |
apt-get install -y libavformat-dev | |
apt-get install -y libswscale-dev | |
apt-get install -y libv4l-dev | |
apt-get install -y libatlas-base-dev | |
apt-get install -y gfortran | |
apt-get install -y libtbb2 | |
apt-get install -y libtbb-dev | |
apt-get install -y libpq-dev | |
apt-get install -y libgtk2.0-dev | |
apt-get install -y libpython3-dev | |
python3 -m pip install numpy | |
cd / | |
wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip | |
unzip /${OPENCV_VERSION}.zip | |
wget https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip -O ${OPENCV_VERSION}-contrib.zip | |
unzip /${OPENCV_VERSION}-contrib.zip | |
mkdir /opencv-${OPENCV_VERSION}/cmake_binary | |
cd /opencv-${OPENCV_VERSION}/cmake_binary \ | |
&& cmake -DBUILD_TIFF=ON \ | |
-DBUILD_opencv_java=OFF \ | |
-DWITH_CUDA=OFF \ | |
-DENABLE_AVX=ON \ | |
-DWITH_OPENGL=ON \ | |
-DWITH_OPENCL=ON \ | |
-DWITH_IPP=ON \ | |
-DWITH_TBB=ON \ | |
-DWITH_EIGEN=ON \ | |
-DWITH_V4L=ON \ | |
-DBUILD_TESTS=OFF \ | |
-DBUILD_PERF_TESTS=OFF \ | |
-DCMAKE_BUILD_TYPE=RELEASE \ | |
-DCMAKE_INSTALL_PREFIX=$(python3.5 -c "import sys; print(sys.prefix)") \ | |
-DPYTHON_EXECUTABLE=$(which python3.5) \ | |
-DPYTHON_INCLUDE_DIR=$(python3.5 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \ | |
-DPYTHON_PACKAGES_PATH=$(python3.5 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \ | |
-DBUILD_EXAMPLES=ON \ | |
-DOPENCV_EXTRA_MODULES_PATH=/opencv_contrib-${OPENCV_VERSION}/modules \ | |
.. \ | |
&& make -j$(nproc) install | |
rm /${OPENCV_VERSION}.zip | |
rm /{OPENCV_VERSION}-contrib.zip | |
mkdir /usr/local/lib/python3.5/site-packages/ | |
ln -s \ | |
/usr/lib/python3.5/dist-packages/cv2/python-3.5/cv2.cpython-35m-x86_64-linux-gnu.so \ | |
/usr/local/lib/python3.5/site-packages/cv2.so |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment