#安装编译依赖
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

#新版本 Ubuntu 的源中没有 libjasper-dev 手动添加源
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev

#创建编译目录:
mkdir opencv-build

#下载 OpenCV 源代码:
git clone https://github.com/Itseez/opencv.git

mkdir build
cd build

#创建 cmake 编译信息:
cmake -DENABLE_VFPV3=ON -DENABLE_VFPV4=ON -DENABLE_NEON=ON -DCMAKE_TOOLCHAIN_FILE=../opencv/platforms/linux/arm-gnueabi.toolchain.cmake ../opencv

#编译:
make -j4
make install

东西都在 ./install 目录下了。

编译自己的应用时注意 opencv2 头文件都是在 opencv4 文件夹下的。 编译参数:

OPENCV_INCLUDE=$(LIBPREFIX)/include/opencv4
-I$(OPENCV_INCLUDE)
-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_flann