144 lines
2.2 KiB
Markdown
144 lines
2.2 KiB
Markdown
### 系统环境配置(编译OpenCV)
|
||
|
||
* 安装 software-properties-common
|
||
|
||
```
|
||
apt install software-properties-common -y
|
||
```
|
||
|
||
* 添加软件源
|
||
|
||
```
|
||
add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main"
|
||
add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe"
|
||
```
|
||
|
||
* 软件源更新
|
||
|
||
```
|
||
apt update
|
||
```
|
||
|
||
* 升级
|
||
|
||
```
|
||
apt upgrade
|
||
```
|
||
|
||
* 安装build-essential、cmake、git和pkg-config
|
||
|
||
```
|
||
apt 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 update
|
||
apt -f install
|
||
apt autoremove -y
|
||
```
|
||
|
||
* 安装jpeg格式图像工具包
|
||
|
||
```
|
||
apt-get install libjpeg8-dev -y
|
||
```
|
||
|
||
|
||
* 安装tif格式图像工具包
|
||
|
||
```
|
||
apt-get install libtiff5-dev -y
|
||
```
|
||
|
||
* 安装JPEG-2000图像工具包
|
||
|
||
```
|
||
apt install libjasper1 libjasper-dev
|
||
```
|
||
|
||
* 安装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
|
||
```
|
||
|
||
<!-- apt install libblas-dev
|
||
apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev -y
|
||
apt install libdc1394-22-dev -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 WITH_GSTREAMER=ON \
|
||
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
|
||
-D CMAKE_INSTALL_PREFIX=install ..
|
||
```
|
||
|
||
* 编译
|
||
```
|
||
make -j4
|
||
```
|
||
|
||
* 安装
|
||
```
|
||
make install
|
||
```
|
||
|
||
* 配置环境变量
|
||
```
|
||
vim /etc/ld.so.conf
|
||
```
|
||
|
||
* 在末尾添加 OpenCV 的 lib 路径
|
||
```
|
||
/usr/local/lib
|
||
```
|
||
|
||
* 更新
|
||
```
|
||
ldconfig
|
||
```
|
||
|
||
* 查看 OpenCV 版本,验证是否配置正确
|
||
```
|
||
pkg-config --modversion opencv
|
||
```
|