Skip to content

Instantly share code, notes, and snippets.

@IKKIson
Forked from SSARCandy/opencv_with_cmake.md
Created February 9, 2018 11:53
Show Gist options
  • Save IKKIson/8bc1072af4c6ff88d375ee24dcb1eb76 to your computer and use it in GitHub Desktop.
Save IKKIson/8bc1072af4c6ff88d375ee24dcb1eb76 to your computer and use it in GitHub Desktop.
Setting up OpenCV(+extra modules) with Cmake step by step tutorial

Setting up OpenCV with Cmake GUI

  1. Download OpenCV and Cmake
  2. Build opencv with cmake image
  • Press configure, choose visual studio 2015, finish
  • Then press generate
  1. Open OpenCV.sln under build/
  2. Build it using Debug, Release
    image
  • right click > build
  • switch to Release mode and build again
  1. [Windows] Setting up environment variable
  • add <opencv>/bin into PATH image
  • add new env named OpenCV_DIR, value as <opencv>/build
  • it may need logout to apply setting, you can check it by echo %PATH%, echo %OpenCV_DIR%

Build with EXTRA MODULES

  1. In step 2. Build opencv with cmake, press configure
  2. Set up OPENCV_EXTRA_MODULES_PATH to proper path(<opencv_contrib>/modules) image
  3. Press configure again, then generate

To see more details instructions, see opencv_contrib README


Travis.yml example

language:
  - cpp

compiler:
  - gcc
  
before_install:
  - sudo apt-get update

install:
  # OpenCV dependencies - Details available at: http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_install/linux_install.html
  - sudo apt-get install -y build-essential
  - sudo apt-get install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
  - sudo apt-get install -y python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

  # Download v3.1.0 .zip file and extract.
  - curl -sL https://github.com/Itseez/opencv/archive/3.1.0.zip > opencv.zip
  - unzip opencv.zip
  
  # Download EXTRA MODULES and extract.
  - curl -sL https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip > opencv_contrib.zip
  - unzip opencv_contrib.zip
  
  # Create a new 'build' folder.
  - cd opencv-3.1.0
  - mkdir build
  - cd build
  
  # Set build instructions for Ubuntu distro.
  - cmake -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.1.0/modules 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 ..
  
  # Run 'make' with four threads.
  - make -j5
  
  # Install to OS.
  - sudo make install
  
  # Add configuration to OpenCV to tell it where the library files are located on the file system (/usr/local/lib)
  - sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
  
  - sudo ldconfig
  - echo "OpenCV installed."
  
  # We need to return to the repo "root" folder, so we can then 'cd' into the C++ project folder.
  - cd ../../

script:
  - cmake CMakeLists.txt
  - make
  - ./a.out
  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment