> For the complete documentation index, see [llms.txt](https://porter.gitbook.io/deep-learning-series/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://porter.gitbook.io/deep-learning-series/index/1.18-opencv-an-zhuang.md).

# 1.18 opencv 安装

## 解决ubuntu 中安装opencv遇到的各种水土不服

* 下载
* 安装

## 下载OpenCV 源码

### 安装依赖包

```
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff5-dev libdc1394-22-dev        
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install libxvidcore-dev libx264-dev    
sudo apt-get install libatlas-base-dev gfortran   
sudo apt-get install ffmpeg
```

作者：BlainWu 来源：CSDN 原文：<https://blog.csdn.net/qq_22945165/article/details/84312374> 版权声明：本文为博主原创文章，转载请附上博文链接！

### 下载、安装

从第三方源中下载（解决官方github下载网速过慢的问题）

```
https://ftp.osuosl.org/pub/blfs/conglomeration/opencv/opencv-3.4.3.zip

（https://ftp.osuosl.org/pub/blfs/conglomeration/opencv/opencv_contrib-3.4.3.tar.gz）#目前这个control不用下载，以后需要可以下载安装
```

* 解压

```
cd /你的解压路径/opencv/
mkdir ./build
```

* cmake

```
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
```

* make

```
make -j4
```

* 安装

```
sudo make install
```

### 编译中会出现的问题

* ippicv\_2017u3\_lnx\_intel64\_general\_20180518.tgz下载失败

进入opencv解压的文件路径中 ---> 找到你的解压路径/opencv-3.4.3/3rdparty/ippicv/ippicv.cmake的文件。

编辑文件：ippicv.cmake

* 编辑ippicv.cmake内容,替换如下的内容

```
ocv_download(FILENAME ${OPENCV_ICV_NAME}
               HASH ${OPENCV_ICV_HASH}
               URL
                 "${OPENCV_IPPICV_URL}"
                 "$ENV{OPENCV_IPPICV_URL}"
                 "file:///home/blain/Downloads/"#
```

> "file:///home/blain/Downloads/"# 这个为你手动下载的文件所在的路径

需手动下载的包的地址如下，自己手动下载，建议存放在opencv解压后的文件夹中方便管理

```
https://ftp.osuosl.org/pub/blfs/conglomeration/opencv/ippicv_2017u3_lnx_intel64_general_20180518.tgz
```

我的下载存放地址就是 home/blain/Downloads 。

修改完成，重新cmake 即可
