树莓派之OpenCV4编译与安装

// 安装依赖
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy python3-dev python3-numpy
sudo apt-get install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
// 下载源码包
https://opencv.org/releases.html

// 编译
unzip opencv-4.0.1.zip
cd opencv-4.0.1
mkdir release
cd release
cmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_GENERATE_PKGCONFIG=ON -DCMAKE_INSTALL_PREFIX=/usr/local ..
make -j4
sudo make install

// 测试
$ python 
>>> import cv2
>>> cv2.__version__
'4.0.1'
>>> 

cd /etc/ld.so.conf.d/
sudo touch opencv4.conf
sudo sh -c 'echo "/usr/local/lib" > opencv4.conf'
ldconfig
INCLUDEPATH += /usr/local/include/opencv4
LIBS += -L/usr/local/lib \
-lopencv_calib3d \
-lopencv_dnn \
-lopencv_flann \
-lopencv_highgui \
-lopencv_imgproc \
-lopencv_objdetect \
-lopencv_stitching \
-lopencv_video \
-lopencv_core \
-lopencv_features2d \
-lopencv_gapi \
-lopencv_imgcodecs \
-lopencv_ml \
-lopencv_photo \
-lopencv_videoio