1.从github上下载源码
https://github.com/opencv/opencv
2.解压
liwq@ubuntu:~/shared/tools$ unzip opencv-4.x.zip
Archive: opencv-4.x.zip
f7ac724c5d2b7f7580e840c4c623609098b17bdc
creating: opencv-4.x/
inflating: opencv-4.x/.editorconfig
creating: opencv-4.x/3rdparty/
creating: opencv-4.x/3rdparty/carotene/
....
inflating: opencv-4.x/samples/wp8/OpenCVXaml/OpenCVXaml/Resources/AppResources.Designer.cs
inflating: opencv-4.x/samples/wp8/OpenCVXaml/OpenCVXaml/Resources/AppResources.resx
inflating: opencv-4.x/samples/wp8/readme.txt
liwq@ubuntu:~/shared/tools$
3.设置环境变量,设置交叉编译链
liwq@ubuntu:~/shared/tools/opencv-4.x$ export PATH=$PATH:/opt/toolchain/aarch64-linux-gnu-linaro-7.5.0/bin
liwq@ubuntu:~/shared/tools/opencv-4.x$ export CC=aarch64-linux-gnu-gcc
liwq@ubuntu:~/shared/tools/opencv-4.x$ export CXX=aarch64-linux-gnu-g++
liwq@ubuntu:~/shared/tools/opencv-4.x$
4.编译
liwq@ubuntu:~/shared/tools/opencv-4.x$ mkdir build
liwq@ubuntu:~/shared/tools/opencv-4.x$ cd build/
liwq@ubuntu:~/shared/tools/opencv-4.x/build$ /home/liwq/shared/tools/cmake-3.5.1-Linux-x86_64/bin/cmake -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake -DCMAKE_INSTALL_PREFIX=../opencv_out ..
liwq@ubuntu:~/shared/tools/opencv-4.x/build$ make install
5.编译成功后,则路径下就生成动态库和头文件了