Skip to content

Instantly share code, notes, and snippets.

@shicai
Created October 15, 2015 08:59
Show Gist options
  • Save shicai/e7f16e8e9b9b90905311 to your computer and use it in GitHub Desktop.
Save shicai/e7f16e8e9b9b90905311 to your computer and use it in GitHub Desktop.
Install OpenCV
# Dan Walkes
# 2014-01-29
# Call this script after configuring variables:
# version - the version of OpenCV to be installed
# downloadfile - the name of the OpenCV download file
# dldir - the download directory (optional, if not specified creates an OpenCV directory in the working dir)
if [[ -z "$version" ]]; then
echo "Please define version before calling `basename $0` or use a wrapper like opencv_latest.sh"
exit 1
fi
if [[ -z "$downloadfile" ]]; then
echo "Please define downloadfile before calling `basename $0` or use a wrapper like opencv_latest.sh"
exit 1
fi
if [[ -z "$dldir" ]]; then
dldir=OpenCV
fi
if ! sudo true; then
echo "You must have root privileges to run this script."
exit 1
fi
set -e
echo "--- Installing OpenCV" $version
echo "--- Installing Dependencies"
source dependencies.sh
echo "--- Downloading OpenCV" $version
mkdir -p $dldir
cd $dldir
wget -O $downloadfile http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/$downloadfile/download
echo "--- Installing OpenCV" $version
echo $downloadfile | grep ".zip"
if [ $? -eq 0 ]; then
unzip $downloadfile
else
tar -xvf $downloadfile
fi
cd opencv-$version
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
make -j 4
sudo make install
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
echo "OpenCV" $version "ready to be used"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment