Skip to content

Instantly share code, notes, and snippets.

@a-sync
Last active November 25, 2021 12:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-sync/276fbb5776ad5d5775d1bd6205e22a4a to your computer and use it in GitHub Desktop.
Save a-sync/276fbb5776ad5d5775d1bd6205e22a4a to your computer and use it in GitHub Desktop.
OpenCV + extra modules install script for Ubuntu 16.04
#!/bin/bash
# https://gist.github.com/a-sync/276fbb5776ad5d5775d1bd6205e22a4a
OPENCV_VERSION="3.4.3"
read -p "Install/update dependencies? ([Yy] or skip this step) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
sudo apt-get -y update
#sudo apt-get -y upgrade
#sudo apt-get -y dist-upgrade
#sudo apt-get -y autoremove
sudo apt-get install -y curl tar build-essential cmake pkg-config python-dev python3-dev python-numpy python3-numpy v4l-utils x264
sudo apt-get install -y zlib1g-dev yasm libatlas-base-dev gfortran libeigen3-dev libgflags-dev libhdf5-dev libgphoto2-dev libv4l-dev libprotobuf-dev protobuf-compiler
sudo apt-get install -y libjpeg8-dev libwebp-dev libtiff5-dev libjasper-dev libpng12-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev
fi
if [ ! -d "opencv-v$OPENCV_VERSION" ]
then
mkdir "opencv-v$OPENCV_VERSION"
curl -L "https://github.com/opencv/opencv/archive/$OPENCV_VERSION.tar.gz" | tar xz --strip=1 -C "opencv-v$OPENCV_VERSION"
fi
if [ ! -d "opencv_contrib-v$OPENCV_VERSION" ]
then
mkdir "opencv_contrib-v$OPENCV_VERSION"
curl -L "https://github.com/opencv/opencv_contrib/archive/$OPENCV_VERSION.tar.gz" | tar xz --strip=1 -C "opencv_contrib-v$OPENCV_VERSION"
fi
cd "opencv-v$OPENCV_VERSION"
rm -rf build
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=RELEASE \
-DOPENCV_ENABLE_NONFREE=ON \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DOPENCV_EXTRA_MODULES_PATH="../../opencv_contrib-v$OPENCV_VERSION/modules" \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_JAVA=OFF ..
#-DCMAKE_CXX_FLAGS=-std=c++11
read -p "Compile and install? ([Yy] or skip this step) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
make -j4
#make -j$(nproc + 1)
sudo make install
sudo ldconfig
fi
echo C libs:
pkg-config --cflags opencv
pkg-config --modversion opencv
echo Python libs:
find /usr/local/lib/ -type f -name "cv2*.so"
python -c 'import cv2; print("python "+cv2.__version__)'
python3 -c 'import cv2; print("python3 "+cv2.__version__)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment