-
-
Save dlime/63759eda46044be94c116435e2d999a5 to your computer and use it in GitHub Desktop.
Build .deb package for OpenCV 4 with Python3 bindings. Optimized for Raspberry PI deep learning purposes (NEON, VFPV3, Eigen3, TBB turned on).
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
#!/usr/bin/env bash | |
MAINTAINER="Dario Limongi" | |
VERSION=4.1.0 | |
# Adapted from https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/ | |
sudo apt update && sudo apt upgrade -y | |
sudo apt-get install -y \ | |
build-essential ccache cmake unzip pkg-config curl \ | |
libjpeg-dev libpng-dev libtiff-dev \ | |
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \ | |
libxvidcore-dev libx264-dev libjasper1 libjasper-dev \ | |
libgtk-3-dev libcanberra-gtk* \ | |
libatlas-base-dev gfortran \ | |
libeigen3-dev libtbb-dev \ | |
python3-dev python3-numpy python-dev python-numpy | |
# Create temporary root directory, download and unzip OpenCV | |
rm -rf ~/opencv-build | |
mkdir ~/opencv-build | |
cd ~/opencv-build | |
curl -L https://github.com/opencv/opencv/archive/${VERSION}.tar.gz | tar xz | |
curl -L https://github.com/opencv/opencv_contrib/archive/${VERSION}.tar.gz | tar xz | |
# Create build folder | |
cd opencv-${VERSION} | |
mkdir build | |
cd build | |
# Configure OpenCV with NEON/VFPV3 arguments + redistributable package install | |
cmake .. \ | |
-DCPACK_BINARY_DEB=ON \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DCMAKE_INSTALL_PREFIX=/usr/local \ | |
-DOPENCV_GENERATE_PKGCONFIG=ON \ | |
-DOPENCV_EXTRA_MODULES_PATH=~/opencv-build/opencv_contrib-${VERSION}/modules \ | |
-DOPENCV_VCSVERSION=${VERSION} \ | |
-DEXTRA_MODULES_VCSVERSION=${VERSION} \ | |
-DBUILD_opencv_python2=ON \ | |
-DBUILD_opencv_python3=ON \ | |
-DBUILD_PERF_TESTS=OFF \ | |
-DBUILD_EXAMPLES=OFF \ | |
-DBUILD_TESTS=OFF \ | |
-DBUILD_PACKAGE=ON \ | |
-DINSTALL_CREATE_DISTRIB=ON \ | |
-DENABLE_NEON=ON \ | |
-DENABLE_VFPV3=ON \ | |
-DOPENCV_ENABLE_NONFREE=ON \ | |
-DWITH_TBB=ON \ | |
-DWITH_EIGEN=ON | |
# Build | |
make -j$(cat /proc/cpuinfo | grep -c 'processor') | |
# Install is required, otherwise cpack will fail to find some libraries | |
sudo make install | |
cpack -G DEB | |
sudo make uninstall | |
echo "To install run: sudo dpkg -i OpenCV-*.deb" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment