1.更新系统
1.sudo apt-get update
2.sudo apt-get upgrade
2.安装一些必要的支持库
2.1 OpenCV的相关工具
sudo apt-get install build-essentia
2.2 OpenCV 图像工具包
sudo apt-get install cmake git pkg-config libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev li.jpg120dev
sudo apt-get update
sudo add-apt-repository --yes ppa:xqms/opencv-nonfree
sudo apt-get update
sudo apt-get install libopencv-nonfree-dev
2.3 安装视频I/O包
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev lib4l-dev
2.4 安装gtk和其他的优化工具包
sudo apt install libgtk2.0-dev libatlas-base-dev gfortran
3 下载编译OpenCV
git clone GitHub - opencv/opencv: Open Source Computer Vision Library
编译安装
cd opencv //切换到目录下
mkdir build //创建release文件夹
sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INTALL_PREFIX=/usr/local/include/opencv4/opencv2 -D OPENCV_ENABLE_NONFREE=ON -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D ENABLE_PRECOMPILED_HEADERS=OFF -D BUILD_EXAMPLES=ON -D CMAKE_CXX_FLAGS="-std=c++11" -D BUILD_opencv_world=ON
-D OPENCV_EXTRA_MODULES_PATH= ../home/ubuntu2/Desktop/opencv/opencv_contrib/modules ..
如果一起编译,在build文件夹里没有发现CONTRIB文件,可以单独编译
sudo make //编译(必须sudo,因为很多文件是只读文件,需要超级权限
sudo make install //安装
sudo ldconfig //更新动态库