Linux搭建OpenCV环境

  1. sudo apt-get install build-essential
  2. sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
  3. sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
  4. git clone https://github.com/opencv/opencv.git
  5. 使用CMake编译OpenCV源代码:
    1. 创建一个临时文件夹,用来存放生成的makefiles。Create a temporary directory, which we denote as <cmake_binary_dir>, where you want to put the generated Makefiles, project files as well the object files and output binaries.
    2. 进入这个临时文件夹:cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local <opencv源代码路径>

  6. 在这个临时文件夹下运行make -j8 # -j8 runs 8 jobs in parallel. Change 8 to number of hardware threads available.
  7. 运行:sudo make install

参考资料:

  1. https://docs.opencv.org/3.0-beta/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation
  2. https://docs.opencv.org/3.4.0/d7/d9f/tutorial_linux_install.html