1.到opencv官网https://opencv.org/releases.html下载需要的opencn安装包,如opencv-3.4.2,解压
unzip opencv-3.4.2.zip
2.进入该文件夹
cd opencv-3.4.2
3.建立文件夹release
mkdir release
4.安装依赖
sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev
5.进入release并编译
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
6.安装
sudo make install