获取源代码 Shell $ git clone https://github.com/opencv/opencv.git 1 $ git clone https://github.com/opencv/opencv.git 安装依赖库 Shell #借助系统自带的opencv简化依赖安装步骤 $ sudo apt-get install libopencv-dev 1 2 #借助系统自带的opencv简化依赖安装步骤 $ sudo apt-get install libopencv-dev 编译源代码 Shell $ cd opencv $ mkdir build $ cd build $ cmake .. $ make -j 10 1 2 3 4 5 6 7 8 9 $ cd opencv $ mkdir build $ cd build $ cmake .. $ make -j 10 替换已经安装的版本 Shell $ sudo make install 1 $ sudo make install 编译出错的处理 如果执行cmake时候出现如下错误信息 Shell CMake Error at CMakeLists.txt:11 (message): FATAL: In-source builds are not allowed. You should create separate directory for build files. -- Configuring incomplete, errors occurred! 1 2 3 4 5 6 7 8 9 10 CMake Error at CMakeLists.txt:11 (message): FATAL: In-source builds are not allowed. You should create separate directory for build files. -- Configuring incomplete, errors occurred! 则应该是在代码根目录下直接执行过cmake,导致根目录下生成了CMakeCache.txt,需要删除CMakeCache.txt再次执行编译即可。