官网获取源码
Source code(tar.gz): https://github.com/opencv/opencv/releases
安装依赖库
- 确保系统安装了cmake
cmake的安装,直接在官网下载文件,解压到指定文件夹,将该文件目录添加到PATH中即可。
- 借助系统自带opencv简化安装步骤
$ sudo apt install -y libopencv-dev
编译源码
$ cd opencv-xx.xx
$ mkdir build
$ cd build
$ cmake ..
$ make
替换系统已经安装的版本
$ sudo make install
**Notes:**如果cmake时,出现一下错误信息
Cmake Error at CMakeList.txt:11(message):
FATAL: In-source builds are not allowed.
You should create separate directory for build files.
-- Configuring incomplete, errors occurred!
则应该是在代码目录中已经存在CMakeCache.txt文件,删除该文件,再次编译即可。