Last active
February 8, 2024 15:43
-
-
Save mcarletti/b14764caad24ccbdb1a44f6b81fb8a97 to your computer and use it in GitHub Desktop.
Compile OpenCV from source
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
#!/bin/bash | |
# Tested on | |
# ------------------------------ | |
# OS Ubuntu 18.04 | |
# Platform x86_64, aarch64 | |
# Python 3.6 | |
if [ $# != 1 ]; then | |
echo -e "Usage:\n\t./build_opencv.sh VERSION\n\nExample:\n\t./build_opencv.sh 4.2.0" | |
exit 1 | |
fi | |
VERSION=$1 | |
ROOT=`pwd` | |
SOURCE_DIR=$ROOT/source | |
INSTALL_DIR=$ROOT/install | |
PLATFORM=`uname -p` | |
mkdir -p $SOURCE_DIR | |
mkdir -p $INSTALL_DIR | |
sudo apt update | |
sudo apt install build-essential | |
sudo apt install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev | |
sudo apt install python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev | |
if [ ! -d $SOURCE_DIR/opencv ]; then | |
cd $SOURCE_DIR | |
git clone https://github.com/opencv/opencv.git | |
fi | |
if [ ! -d $SOURCE_DIR/opencv_contrib ]; then | |
cd $SOURCE_DIR | |
git clone https://github.com/opencv/opencv_contrib.git | |
fi | |
cd $SOURCE_DIR/opencv | |
git checkout $VERSION | |
cd $SOURCE_DIR/opencv_contrib | |
git checkout $VERSION | |
mkdir -p $ROOT/build/opencv-$VERSION | |
cd $ROOT/build/opencv-$VERSION | |
cmake $SOURCE_DIR/opencv \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \ | |
-DOPENCV_EXTRA_MODULES_PATH=$SOURCE_DIR/opencv_contrib/modules \ | |
-DOPENCV_ENABLE_NONFREE=ON \ | |
-DWITH_CUDA=ON \ | |
-DWITH_FFMPEG=ON \ | |
-DWITH_GSTREAMER=ON \ | |
-DBUILD_opencv_cudacodec=OFF \ | |
-DBUILD_opencv_python2=OFF \ | |
-DBUILD_opencv_python3=ON \ | |
-DPYTHON_PACKAGES_PATH=$INSTALL_DIR/python \ | |
-DPYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3.6 \ | |
-DPYTHON3_EXECUTABLE=/usr/bin/python3.6 \ | |
-DPYTHON3_INCLUDE_DIR=/usr/include/python3.6m \ | |
-DPYTHON3_LIBRARY=/usr/lib/$PLATFORM-linux-gnu/libpython3.6m.so.1.0 \ | |
-DPYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.6/dist-packages/numpy/core/include \ | |
-DBUILD_DOCS=OFF \ | |
-DBUILD_EXAMPLES=OFF \ | |
-DBUILD_TESTS=OFF | |
make -j8 | |
make install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment