ubuntu命令安装opencv
时间: 2023-11-04 15:56:21 浏览: 138
在Ubuntu上安装OpenCV的命令如下:
1. 使用git下载OpenCV源码:
```shell
git clone https://github.com/opencv/opencv.git
```
2. 进入下载的OpenCV目录,并创建build目录:
```shell
cd opencv
mkdir build
cd build
```
3. 使用cmake进行编译配置:
```shell
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_GENERATE_PKGCONFIG=ON ..
```
4. 编译OpenCV(使用-j参数可以加快编译速度,具体数值可以根据CPU核心数进行调整):
```shell
make -j8
```
5. 安装编译好的OpenCV库:
```shell
sudo make install
```
6. 配置动态库路径:
```shell
sudo gedit /etc/ld.so.conf.d/opencv.conf
```
在打开的文件中添加以下内容:
```
/usr/local/lib
```
保存并关闭文件,然后执行以下命令使配置生效:
```shell
sudo ldconfig
```
7. 配置pkg-config路径:
```shell
sudo gedit /etc/bash.bashrc
```
在打开的文件末尾添加以下内容:
```
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
```
保存并关闭文件,然后执行以下命令更新环境变量:
```shell
source /etc/bash.bashrc
sudo updatedb
```
现在,你已经成功地在Ubuntu上安装了OpenCV。
阅读全文
相关推荐


















