OpenCV 3.4 的編譯跟 2.4 的差不多,如果沒有特殊需求連 contrib 都可以不用裝
sudo apt install build-essential -y
sudo apt install cmake cmake-qt-gui git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev -y
sudo apt install python-dev python-numpy python3-dev python3-pip libtbb2 libtbb-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libdc1394-22-dev qt5-default libopenblas-dev -y
git clone https://github.com/opencv/opencv.git
cd ~/Git/opencv/build
make -j8
sudo make install
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
int main(int argc, char **argv){
Mat img = imread(argv[1]);
imshow("show", img);
waitKey(6000);
return 0;
}
g++ test.cpp `pkg-config opencv --cflags` `pkg-config opencv --libs` -o test
./test ~/Git/opencv/samples/c/lena.jpg
如果看到 Lenna 出現,就代表 OpenCV 安裝完成
python
import cv2
cv2.__Version__
exit()