1、安装依赖
CentOS:
yum install gcc gcc-c++ gtk2-devel gimp-develgimp-devel-tools gimp-help-browser zlib-devel libtiff-devel libjpeg-devellibpng-devel gstreamer-devel libavc1394-devel libraw1394-devel libdc1394-develjasper-devel jasper-utils swig python libtool nasm
sudo yum install pngquant
sudo yum -y install libpng*
sudo yum install libpng-devel
Ubuntu:
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
2、下载opencv
https://github.com/opencv/opencv.git
或 git clone https://github.com/opencv/opencv.git
3、编译
cd opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make
sudo make install
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
4、测试安装
切换到samples目录下面,并编译samples程序
cd ../samples/
sudo cmake .
sudo make -j $(nproc)
然后切换到cpp目录下运行测试程序
cd cpp/
./cpp-example-facedetect XX (图片路径)
显示图像,测试成功
参考:https://www.jianshu.com/p/0b25b8531a3c
https://blog.csdn.net/haigui_li/article/details/52492773