127 lines
1.9 KiB
Markdown
127 lines
1.9 KiB
Markdown
|
# 系统环境配置(编译OpenCV)
|
|||
|
|
|||
|
* 安装 software-properties-common
|
|||
|
|
|||
|
```
|
|||
|
apt-get install software-properties-common
|
|||
|
```
|
|||
|
|
|||
|
* 添加软件源
|
|||
|
|
|||
|
```
|
|||
|
add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main"
|
|||
|
```
|
|||
|
|
|||
|
* 软件源更新
|
|||
|
|
|||
|
```
|
|||
|
sudo apt-get update
|
|||
|
```
|
|||
|
|
|||
|
* 升级
|
|||
|
|
|||
|
```
|
|||
|
apt-get upgrade
|
|||
|
```
|
|||
|
|
|||
|
* 安装build-essential、cmake、git和pkg-config
|
|||
|
|
|||
|
```
|
|||
|
apt-get install build-essential cmake git pkg-config -y
|
|||
|
```
|
|||
|
|
|||
|
出现错误:
|
|||
|
![错误信息](image/CC706F1B-4AE8-477D-8275-52AC498D1966.png)
|
|||
|
|
|||
|
```
|
|||
|
mv /var/lib/dpkg/info/ /var/lib/dpkg/info_old/
|
|||
|
mkdir /var/lib/dpkg/info/
|
|||
|
apt-get update
|
|||
|
apt-get -f install
|
|||
|
apt autoremove
|
|||
|
```
|
|||
|
|
|||
|
* 安装jpeg格式图像工具包
|
|||
|
|
|||
|
```
|
|||
|
apt-get install libjpeg8-dev -y
|
|||
|
```
|
|||
|
|
|||
|
|
|||
|
* 安装tif格式图像工具包
|
|||
|
|
|||
|
```
|
|||
|
apt-get install libtiff5-dev -y
|
|||
|
```
|
|||
|
|
|||
|
* 安装JPEG-2000图像工具包
|
|||
|
|
|||
|
```
|
|||
|
apt-get install libjasper-dev -y
|
|||
|
```
|
|||
|
|
|||
|
* 安装png图像工具包
|
|||
|
|
|||
|
```
|
|||
|
apt-get install libpng-dev -y
|
|||
|
```
|
|||
|
|
|||
|
* 安装视频 I/O 包
|
|||
|
|
|||
|
```
|
|||
|
apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y
|
|||
|
```
|
|||
|
|
|||
|
* 安装 gtk2.0,这一步比较麻烦,如果一直无法安装成功可尝试将apt-get切换为国内镜像源
|
|||
|
```
|
|||
|
apt-get install libgtk2.0-dev -y
|
|||
|
```
|
|||
|
|
|||
|
* 安装优化函数包
|
|||
|
```
|
|||
|
apt-get install libatlas-base-dev gfortran -y
|
|||
|
```
|
|||
|
|
|||
|
* 解压
|
|||
|
```
|
|||
|
tar -xvf opencv-3.4.12.tar
|
|||
|
cd opencv-3.4.12/
|
|||
|
mkdir build
|
|||
|
cd build
|
|||
|
```
|
|||
|
|
|||
|
* 配置CMake
|
|||
|
```
|
|||
|
cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D BUILD_PNG=NO -D BUILD_JASPER=NO -D BUILD_TIFF=NO -D WITH_PNG=NO -D WITH_JASPER=NO -D WITH_TIFF=NO -D CMAKE_INSTALL_PREFIX=/usr/local ..
|
|||
|
```
|
|||
|
|
|||
|
* 编译
|
|||
|
```
|
|||
|
make -j4
|
|||
|
```
|
|||
|
|
|||
|
* 安装
|
|||
|
```
|
|||
|
make install
|
|||
|
```
|
|||
|
|
|||
|
* 配置环境变量
|
|||
|
```
|
|||
|
vim /etc/ld.so.conf
|
|||
|
```
|
|||
|
|
|||
|
* 在末尾添加 OpenCV 的 lib 路径
|
|||
|
```
|
|||
|
/usr/local/lib
|
|||
|
```
|
|||
|
|
|||
|
* 更新
|
|||
|
```
|
|||
|
ldconfig
|
|||
|
```
|
|||
|
|
|||
|
* 查看 OpenCV 版本,验证是否配置正确
|
|||
|
```
|
|||
|
pkg-config --modversion opencv
|
|||
|
```
|