How to compile OpenCV using Ubuntu 16.04

  1. Install the required packages: $ sudo apt install build-essential cmake cmake-gui git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
  2. Download the source code of OpenCV (prefer last stable version: OpenCV 3.1)
  3. Create folders “OpenCV/src” and “OpenCV/build” in your home directory
  4. Copy all the data of the OpenCV downloaded file in “home/OpenCV/src”
  5. Launch cMakeGUI
  6. Set the build and source folder newly created
  7. Click on Configure button
  8. In Compile WITH remove CUDA and check QtCreator
  9. Change the install prefix of cMake (it’s useful because if you want to compile many version of OpenCV source code you can keep separate)
  10. Set the Qt5 library (You must after install QtCreator). They would be in a similar path: “/Qt5.7.0/5.7/gcc_64/lib/cmake/Qt5Widgets”
  11. OPTIONAL: you can set the extra modules  path of OpenCV like opencv_contrib_modules that contain the SIFT, SURF implementation. Before you must download it from GitHub (pay attention about downloading the correct version of extra modules, the one that matches with the version of your openCV. Please check this page)
  12. Remove from the BUILD group: BUILD_opencv_aruco, BUILD_opencv_optflow and BUILD_opencv_python2
  13. Click on Configure button
  14. Click on Generate button
  15. Using the terminal enter in the build folder (with cd commands) and launch a make command ($ make)
  16. After a long time and if you don’t have any error you can launch the make install ($ make install).