opencv基本上是搞CV必备套件之一了,支持的语言也非常多,但是安装起来有点麻烦。
安装官方给的opencv依赖包
- GCC 4.4.x or later
- CMake 2.6 or higher
- Git
- GTK+2.x or higher, including headers (libgtk2.0-dev) # 控制opencv GUI
- pkg-config
- Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
- ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
- [optional] libtbb2 libtbb-dev
- [optional] libdc1394 2.x
- [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
第一步骤:先把所有的依赖都给安装了
$ 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 libtiff-dev libjasper-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 # 优化opencv功能
$ sudo apt-get install ffmpeg
第二步骤:去官网下载opencv3.4.1
官网地址:https://opencv.org/releases/ 下载完成之后直接解压将opencv3.4.1放在home目录下
$cd opencv-3.4.1
$mkdir build
$cd build
第三步骤:编译安装
生成编译文件变革指定路径:
$
cmake -
D CMAKE_BUILD_TYPE
=
Release
-
D CMAKE_INSTALL_PREFIX
=
/
usr
/
local ..
这里将目标安装到/usr/local这个路径下
编译:
$ make
这里可能要等很长的时间(安装的时候本人遇到了一个问题,详见连接:
https://blog.csdn.net/Chris_zhangrx/article/details/85245610
)
and a TIF problem
解决TIF问题:
$sudo apt-get autoremove libtiff5-dev
sudo apt-get install lib4(此时按tab键补全)
安装:
$make install
看到这个界面说明opencv安装没有问题了
第四步骤:设置相关的配置
1.用sudo打开ld.so.conf文件:
$sudo gedit /etc/ld.so.conf
在文件最后中加上一行 /usr/local/lib
2、运行:
$sudo ldconfig
3、修改bash.bashrc文件:
$sudo vim /etc/bash.bashrc
4、在文件末尾加入:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
5、最后执行:
$source /etc/bash.bashrc
至此所有的配置都已经完成,下面用一个小程序测试一下:
cd到opencv-3.4.1/samples/cpp/example_cmake目录下,可以看到这个目录里官方已经给出了一个cmake的example,我们可以拿来测试下,按顺序执行:
$cmake .
$make
$./opencv_example
即可看到打开了摄像头,在左上角有一个hello opencv,即表示配置成功。
opencv-contrib的安装
从官方网站下载对应版本的opencv-contrib,解压并放置在opencv的目录下,下载地址在开头
进入opencv下的build文件夹
$cd opencv/build
编译
$sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules/ ..
参考链接:https://blog.csdn.net/li_wen01/article/details/71641408
https://blog.csdn.net/GSH_Hello_World/article/details/80424829
https://blog.csdn.net/evil_xue/article/details/85081005
https://blog.csdn.net/xiangxianghehe/article/details/78780269