├── README.md └── install.sh /README.md: -------------------------------------------------------------------------------- 1 | # Latest OpenCV Installer From Source. 2 | 3 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/whizzzkid/opencv-complete-build-cuda/pulls) 4 | [![Code Climate](https://lima.codeclimate.com/github/whizzzkid/opencv-complete-build-cuda/badges/gpa.svg)](https://lima.codeclimate.com/github/whizzzkid/opencv-complete-build-cuda) 5 | [![Issue Count](https://lima.codeclimate.com/github/whizzzkid/opencv-complete-build-cuda/badges/issue_count.svg)](https://lima.codeclimate.com/github/whizzzkid/opencv-complete-build-cuda) 6 | 7 | Full build script for Open CV with/without cuda and bumblebee support. 8 | 9 | ## Need 10 | After playing around with so many parameters and building OpenCV from source, I 11 | realized how painful this was. I ended up creating an installer script for my 12 | convienience and since now I feel pretty confident that I have perfected this, I 13 | am relasing this to everyone so your life can be simpler too. 14 | 15 | ## Short Link 16 | The install script is located at: [http://bit.ly/OpenCV-Latest](http://bit.ly/OpenCV-Latest) 17 | 18 | ## Installation 19 | One Line Install: 20 | 21 | `$ curl -fsSL http://bit.ly/OpenCV-Latest | bash -s /path/to/download/folder` 22 | 23 | One Line Install With Bumblebee: 24 | 25 | `$ curl -fsSL http://bit.ly/OpenCV-Latest | optirun bash -s /path/to/download/folder` 26 | 27 | ## Fetching Updates 28 | One Line Install: 29 | 30 | `$ curl -fsSL http://bit.ly/OpenCV-Latest | bash -s /existing/download/path` 31 | 32 | One Line Install With Bumblebee: 33 | 34 | `$ curl -fsSL http://bit.ly/OpenCV-Latest | optirun bash -s /existing/download/path` 35 | 36 | ## Pre Install 37 | You need to have the curl package to issue the online install. 38 | 39 | `$ sudo apt install curl` 40 | 41 | ## Post Install 42 | Make sure to setup relevant paths for python so that OpenCV packages can be 43 | accessed. Generally the the path will be: 44 | 45 | `$HOME/.opencv/lib/pythonX.X/dist-package` 46 | 47 | Where X.X = {2.7, 3.2}. If your system does not have $PYTHONPATH variable, set 48 | this in your profile. 49 | 50 | ## Features 51 | This script will download and install everything required by OpenCV and build 52 | everything fresh. In case you already have the repos downloaded and just want 53 | to refresh the latest build. Simply provide the same download path and 54 | everything latest will be pulled in. 55 | 56 | ## License 57 | GPLv3 58 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Run: $ curl -fsSL http://bit.ly/OpenCV-Latest | [optirun] bash -s /path/to/download/folder 3 | # Install libeigen3-dev: http://launchpadlibrarian.net/356350632/libeigen3-dev_3.3.4-4_all.deb 4 | # Run: sudo ln -s /usr/lib/nvidia-387/libnvcuvid.so /usr/lib/libnvcuvid.so 5 | # Run: sudo ln -s /usr/lib/nvidia-387/libnvcuvid.so.1 /usr/lib/libnvcuvid.so.1 6 | set -e 7 | RESET='\033[0m' 8 | COLOR='\033[1;32m' 9 | 10 | function msg { 11 | echo -e "${COLOR}$(date): $1${RESET}" 12 | } 13 | 14 | function fail { 15 | msg "Error : $?" 16 | exit 1 17 | } 18 | 19 | function mcd { 20 | mkdir -p "$1" || fail 21 | cd "$1" || fail 22 | } 23 | 24 | if [ -z "$1" ]; then 25 | msg "No Download Path Specified" 26 | fi 27 | 28 | # Script 29 | msg "Installation Started" 30 | 31 | INSTALL_PATH="/usr/local/opencv" 32 | msg "OpenCV will be installed in $INSTALL_PATH" 33 | 34 | DOWNLOAD_PATH=$1 35 | msg "OpenCV will be downloaded in $DOWNLOAD_PATH" 36 | 37 | CUDA_PATH="/usr/local/cuda" 38 | 39 | msg "Updating system before installing new packages." 40 | sudo add-apt-repository -y ppa:jonathonf/ffmpeg-3 || fail 41 | sudo apt -y update || fail 42 | sudo apt -y upgrade || fail 43 | sudo apt -y dist-upgrade || fail 44 | sudo apt -y autoremove || fail 45 | sudo apt -y autoclean || fail 46 | 47 | msg "Installing build tools." 48 | sudo apt install -y \ 49 | build-essential \ 50 | cmake \ 51 | git \ 52 | || fail 53 | 54 | msg "Installing GUI components." 55 | sudo apt install -y \ 56 | libharfbuzz-dev \ 57 | libvtk6-dev \ 58 | python-vtk6 \ 59 | qt5-default \ 60 | || fail 61 | 62 | msg "Installing media I/O componenets." 63 | sudo apt install -y \ 64 | libavresample-dev \ 65 | libgdal-dev \ 66 | libgphoto2-dev \ 67 | libjasper-dev \ 68 | libjpeg-dev \ 69 | libopenexr-dev \ 70 | libpng-dev \ 71 | libtiff5-dev \ 72 | libwebp-dev \ 73 | zlib1g-dev \ 74 | || fail 75 | 76 | msg "Installing video I/O components." 77 | sudo apt install -y \ 78 | libavcodec-dev \ 79 | libavformat-dev \ 80 | libdc1394-22-dev \ 81 | libopencore-amrnb-dev \ 82 | libopencore-amrwb-dev \ 83 | libswscale-dev \ 84 | libtheora-dev \ 85 | libv4l-dev \ 86 | libvorbis-dev \ 87 | libx264-dev \ 88 | libxine2 \ 89 | libxine2-dev \ 90 | libxvidcore-dev \ 91 | yasm \ 92 | || fail 93 | 94 | msg "Installing Streaming Components." 95 | sudo apt install -y \ 96 | gstreamer1.0-doc \ 97 | gstreamer1.0-libav \ 98 | gstreamer1.0-plugins-bad \ 99 | gstreamer1.0-plugins-base \ 100 | gstreamer1.0-plugins-good \ 101 | gstreamer1.0-plugins-ugly \ 102 | gstreamer1.0-tools \ 103 | libgstreamer1.0-0 \ 104 | libgstreamer1.0-dev \ 105 | libgstreamer-plugins-bad1.0-dev \ 106 | libgstreamer-plugins-base1.0-dev \ 107 | libgstreamer-plugins-good1.0-dev \ 108 | || fail 109 | 110 | msg "Installing Linear Algebra and Parallelism libs." 111 | sudo apt install -y \ 112 | libboost-all-dev \ 113 | libfftw3-dev \ 114 | libfftw3-mpi-dev \ 115 | libmpfr-dev \ 116 | libopenblas-dev \ 117 | libsuperlu-dev \ 118 | libtbb-dev \ 119 | || fail 120 | 121 | 122 | msg "Installing LAPACKE libs." 123 | sudo apt install -y \ 124 | checkinstall \ 125 | liblapacke-dev \ 126 | || fail 127 | 128 | msg "Installing SFM components." 129 | sudo apt install -y \ 130 | libatlas-base-dev \ 131 | libgflags-dev \ 132 | libgoogle-glog-dev \ 133 | libsuitesparse-dev \ 134 | || fail 135 | 136 | msg "Installing Python." 137 | sudo apt install -y \ 138 | pylint \ 139 | python-dev \ 140 | python-numpy \ 141 | python-tk \ 142 | python3-dev \ 143 | python3-numpy \ 144 | python3-tk \ 145 | || fail 146 | 147 | msg "Installing JDK." 148 | sudo apt install -y \ 149 | ant \ 150 | default-jdk \ 151 | || fail 152 | 153 | msg "Installing Docs." 154 | sudo apt install -y doxygen || fail 155 | 156 | msg "All deps installed. Continuing with installation" 157 | 158 | # Downloading 159 | cd $DOWNLOAD_PATH 160 | 161 | REPOS="ceres-solver,https://ceres-solver.googlesource.com/ceres-solver 162 | opencv,https://github.com/opencv/opencv.git 163 | opencv_contrib,https://github.com/opencv/opencv_contrib.git 164 | opencv_extra,https://github.com/opencv/opencv_extra.git" 165 | 166 | for repo in $REPOS; do 167 | IFS="," 168 | set $repo 169 | if [[ -D$1 && -x $1 ]]; then 170 | msg "Updating $1 Repo." 171 | cd $1 172 | git pull || fail 173 | cd .. 174 | else 175 | msg "Downloading $1 Package" 176 | git clone $2 || fail 177 | fi 178 | done 179 | 180 | msg "Configuring Ceres Solver." 181 | mcd ceres-solver/build 182 | cmake \ 183 | -DCMAKE_C_FLAGS="-fPIC" \ 184 | -DCMAKE_CXX_FLAGS="-fPIC" \ 185 | -DBUILD_EXAMPLES=OFF \ 186 | -DBUILD_SHARED_LIBS=ON \ 187 | .. || fail 188 | 189 | msg "Making Ceres Solver." 190 | make -j $(($(nproc)+1)) || fail 191 | make -j $(($(nproc)+1)) test || fail 192 | msg "Installing Ceres Solver." 193 | 194 | sudo make -j $(($(nproc)+1)) install || fail 195 | cd $DOWNLOAD_PATH 196 | 197 | sudo rm -rf opencv/build || fail 198 | mcd opencv/build || fail 199 | 200 | # Configuring make 201 | msg "Configuring OpenCV Make" 202 | cmake \ 203 | -DBUILD_EXAMPLES=ON \ 204 | -DBUILD_OPENCV_JAVA=OFF \ 205 | -DBUILD_OPENCV_JS=ON \ 206 | -DBUILD_OPENCV_NONFREE=ON \ 207 | -DBUILD_OPENCV_PYTHON=ON \ 208 | -DCMAKE_BUILD_TYPE=RELEASE \ 209 | -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH \ 210 | -DCMAKE_LIBRARY_PATH=$CUDA_PATH/lib64/stubs/ \ 211 | -DCUDA_CUDA_LIBRARY=$CUDA_PATH/lib64/stubs/libcuda.so \ 212 | -DCUDA_FAST_MATH=ON \ 213 | -DCUDA_TOOLKIT_ROOT_DIR=$CUDA_PATH \ 214 | -DENABLE_CCACHE=ON \ 215 | -DENABLE_FAST_MATH=ON \ 216 | -DENABLE_PRECOMPILED_HEADERS=OFF \ 217 | -DINSTALL_C_EXAMPLES=ON \ 218 | -DINSTALL_PYTHON_EXAMPLES=ON \ 219 | -DINSTALL_TESTS=ON \ 220 | -DOPENCV_EXTRA_MODULES_PATH=$DOWNLOAD_PATH/opencv_contrib/modules/ \ 221 | -DOPENCV_ENABLE_NONFREE=ON \ 222 | -DOPENCV_TEST_DATA_PATH=$DOWNLOAD_PATH/opencv_extra/testdata/ \ 223 | -DWITH_CUBLAS=ON \ 224 | -DWITH_CUDA=ON \ 225 | -DWITH_FFMPEG=ON \ 226 | -DWITH_GDAL=ON \ 227 | -DWITH_GSTREAMER=ON \ 228 | -DWITH_LIBV4L=ON \ 229 | -DWITH_NVCUVID=ON \ 230 | -DWITH_OPENCL=ON \ 231 | -DWITH_OPENGL=ON \ 232 | -DWITH_QT=ON \ 233 | -DWITH_TBB=ON \ 234 | -DWITH_V4L=ON \ 235 | -DWITH_VTK=ON \ 236 | -DWITH_XINE=ON \ 237 | .. || fail 238 | 239 | # Making 240 | msg "Building OpenCV." 241 | make -j $(($(nproc)+1)) || fail 242 | make -j $(($(nproc)+1)) test || fail 243 | 244 | msg "Installing OpenCV" 245 | sudo make -j $(($(nproc)+1)) install || fail 246 | sudo ldconfig || fail 247 | 248 | # Finished 249 | msg "Installation finished for OpenCV" 250 | msg "Please Add $INSTALL_PATH/lib/pythonX.X/dist-packages/ to your PYTHONPATH" 251 | --------------------------------------------------------------------------------