操作系統信息
jwllinux@jwlLinux ~ $ uname -a Linux jwlLinux 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:34:49 UTC 2016 i686 i686 i686 GNU/Linux |
jwllinux@jwlLinux ~ $ lsb_release -a LSB Version: core-9.20160110ubuntu0.2-ia32:core-9.20160110ubuntu0.2-noarch:cxx-3.0-ia32:cxx-3.0-noarch:cxx-3.1-ia32:cxx-3.1-noarch:cxx-3.2-ia32:cxx-3.2-noarch:cxx-4.0-ia32:cxx-4.0-noarch:cxx-4.1-ia32:cxx-4.1-noarch:security-9.20160110ubuntu0.2-ia32:security-9.20160110ubuntu0.2-noarch Distributor ID: LinuxMint Description: Linux Mint 18 Sarah Release: 18 Codename: sarah |
下載opencv3. 4.10源碼
下載鏈接:https://opencv.org/releases/
opencv-3.4.10.zip
依賴包安裝
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install pkg-config libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev |
|
sudo apt-get install libtbb2 libtbb-dev |
TBB:Thread Building Blocks線程構建模塊 |
sudo apt install qtbase5-dev |
|
主要工具版本
jwllinux@jwlLinux ~/Downloads $ cmake -version cmake version 3.5.1 |
jwllinux@jwlLinux ~/Downloads $ make -v GNU Make 4.1 |
jwllinux@jwlLinux ~/Downloads $ gcc --version gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609 |
jwllinux@jwlLinux ~/Downloads $ g++ --version g++ (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609 Copyright (C) 2015 Free Software Foundation, Inc. |
jwllinux@jwlLinux ~/Downloads $ git --version git version 2.7.4 |
解壓組織、編譯、安裝
解壓文件,新建一個文件夾用於安放編譯結果,然後安裝(選擇安裝在/usr/local下面)
$ unzip opencv-3.4.10.zip
$ cd opencv-3.4.10
$ mkdir release
$ cd release
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=OFF -D WITH_OPENGL=OFF ..
說明:
這裏面主要是 CMake的一些配置項,最後的‘..’ 表示到上層目錄下去找CMakeLists.txt文件,筆者看了下OpenCV項目提供的CMakeLists.txt文件,相對複雜,就不過多介紹了。
另外,知乎文檔評價CMake,學習曲線確實高。鏈接如下:
cmake -D |
-D <var>:<type>=<value>, -D <var>=<value> Create a cmake cache entry. |
.. |
表示CMakeLists.txt在上層目錄 |
執行完後,會產生整個OpenCV項目的構建文件(build),輸出如下:
$ make -j $(nproc)
// make -j 多核處理器進行編譯(默認的make只用一核,很慢),$(nproc)返回自己機器的核數
$ make install //把編譯結果安裝到 /usr/local的 lib/ 和 include/下面
可能遇到的問題
CMake Error at CMakeLists.txt:20 (find_package):By not providing "FindQt5Core.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt5Core", but CMake did not find one.Could not find a package configuration file provided by "Qt5Core" with any of the following names: Qt5CoreConfig.cmake qt5core-config.cmake Add the installation prefix of "Qt5Core" to CMAKE_PREFIX_PATH or set "Qt5Core_DIR" to a directory containing one of the above files.If "Qt5Core" provides a separate development package or SDK, be sure it has been installed. |
解決方案:
需要安裝包qtbase5-dev。
$ sudo apt install qtbase5-dev |
方案二:
Cmake構建選項中,將-D WITH_QT=OFF 填爲OFF
至於此構建選項對編譯處理的OpenCV的影響,筆者後續用到後再作詳細分析。