Skip to content

Instantly share code, notes, and snippets.

@jmg-duarte
Created September 4, 2020 11:11
Show Gist options
  • Save jmg-duarte/5c9747aef94d1660cf9b94c294f4a4c5 to your computer and use it in GitHub Desktop.
Save jmg-duarte/5c9747aef94d1660cf9b94c294f4a4c5 to your computer and use it in GitHub Desktop.
Setup OpenCV with an Anaconda environment
#!/bin/bash
function install_dependencies {
echo "installing dependencies"
sudo apt update
sudo apt install -y \
build-essential \
cmake \
git \
libgtk2.0-dev \
pkg-config \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer1.0-dev \
libgtk2.0-dev \
libgtk-3-dev \
libpng-dev \
libjpeg-dev \
libopenexr-dev \
libtiff-dev \
libwebp-dev
}
function clone_opencv {
mkdir opencv/
cd opencv/ || exit
git clone https://github.com/opencv/opencv.git
git checkout tags/4.4.0
git clone https://github.com/opencv/opencv_contrib.git
cd ../ || exit
}
function build_opencv {
ANACONDA_ENV="$HOME/anaconda3/envs/thesis-ocv-38"
cd opencv/ || exit
mkdir build
cd build || exit
cmake \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_OPENMP=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_python_bindings_generator=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D PYTHON_DEFAULT_EXECUTABLE="$ANACONDA_ENV/bin/python3" \
-D PYTHON3_EXECUTABLE="$ANACONDA_ENV/bin/python" \
-D PYTHON3_INCLUDE_DIR="$ANACONDA_ENV/include/python3.8" \
-D PYTHON3_LIBRARY="$ANACONDA_ENV/lib/libpython3.8.so" \
-D PYTHON3_NUMPY_INCLUDE_DIRS="$ANACONDA_ENV/lib/python3.8/site-packages/numpy/core/include" \
-D PYTHON3_PACKAGES_PATH="$ANACONDA_ENV/lib/python3.8/site-packages" \
-D WITH_JULIA=ON \
-D Julia_EXECUTABLE="$HOME/.julia-1.5.1/bin/julia" \
-D OPENCV_EXTRA_MODULES_PATH="$PWD/../opencv_contrib/modules" \
-D OPENCV_ENABLE_NONFREE=ON \
../opencv/
# -D JULIA_PKG_INSTALL_PATH="$HOME/.julia/packages" \
make -j 8
sudo make install
}
while test $# -gt 0; do
case "$1" in
--deps)
shift
install_dependencies
;;
--clone)
shift
clone_opencv
;;
--build)
shift
build_opencv
;;
--full)
shift
install_dependencies
clone_opencv
build_opencv
exit
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment