Build OpenCV 3 on Ubuntu

系統環境

  • Ubuntu 16.04
  • OpenCV 3.3.1
  • Cmake

目錄放置結構

1
2
|- opencv-3.3.1
|- opencv_contrib-3.3.1

opencv-3.3.1 原始碼下載
opencv_contrib-3.3.1 原始碼下載

編譯時所需要的套件

1
sudo apt-get install build-essential cmake git

可以參考這些(待確認)
https://docs.opencv.org/3.3.0/d7/d9f/tutorial_linux_install.html
https://docs.opencv.org/3.4.1/d2/de6/tutorial_py_setup_in_ubuntu.html (套件有錯誤)
https://www.learnopencv.com/install-opencv-3-4-4-on-ubuntu-16-04/

編譯 OpenCV

編譯 opencv-3.3.1,

1
2
3
4
5
6
7
8
9
10
11
12
cd opencv-3.3.1
mkdir -p build && cd build
cmake \
-DCMAKE_BUILD_TYPE:STRING=RELEASE \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local \
-DWITH_TBB:BOOL=ON \
-DWITH_V4L:BOOL=ON \
-DBUILD_EXAMPLES:BOOL=ON \
-DWITH_QT:BOOL=ON \
-DWITH_OPENGL:BOOL=ON \
..
make -j8

安裝,

1
sudo make install

重新載入動態連結,

1
sudo ldconfig -v

編譯 OpenCV (with opencv_contrib)

編譯 opencv-3.3.1 with opencv_contrib,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cd opencv-3.3.1
mkdir -p build && cd build
cmake \
-DCMAKE_BUILD_TYPE:STRING=RELEASE \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local \
-DWITH_TBB:BOOL=ON \
-DWITH_V4L:BOOL=ON \
-DBUILD_EXAMPLES:BOOL=ON \
-DWITH_QT:BOOL=ON \
-DWITH_OPENGL:BOOL=ON \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.3.1/modules \
-DBUILD_opencv_legacy=OFF \
..
make -j8

安裝,

1
sudo make install

重新載入動態連結,

1
sudo ldconfig -v