主要内容
Opencv3.2 python2.7 的CentOS7 完整安装过程。 yum安装的opencv 是2.4 版本;为使用最新功能,下面介绍 源码安装 Opencv3。
……
系统环境
1 2 3 4 5 6 7 8
| ╭─root@localhost ~ ╰─ Linux localhost.localdomain 3.10.0-514.21.1.el7.x86_64 ╭─root@localhost ~ ╰─ CentOS Linux release 7.3.1611 (Core)
|
软件源
1
| wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
|
1
| yum -y install epel-release && rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
|
软件环境
编译opencv需要的软件包
- GCC 4.4.x or later
- CMake 2.8.7 or higher
- Git
- GTK+2.x or higher
- pkg-config
- Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
- ffmpeg and development packages
- [optional] libtbb2 libtbb-dev
- [optional] libdc1394 2.x
- [optional] libdc1394-devel libv4l-devel gstreamer-plugins-base-devel
- [optional] CUDA Toolkit 6.5 or higher
更新系统
开发工具
1
| yum groupinstall 'Development Tools'
|
1
| yum install cmake cmake-gui git pkgconfig autoconf automake freetype-devel gcc gcc-c++ libtool make mercurial nasm pkgconfig zlib-devel
|
视频和图像格式
#图像
1
| yum install libpng-devel libjpeg-turbo-devel jasper-devel openexr-devel libtiff-devel libwebp-devel
|
#视频
1
| yum install libdc1394-devel libv4l-devel gstreamer-plugins-base-devel ffmpeg ffmpeg-devel
|
GUI特征
Threading Building Blocks (TBB)
1
| yum install tbb-devel eigen3-devel
|
cuda安装
//TODO
vlc
python
centos 7 默认安装的是 python 2.7
pip (python package manager)
1 2
| curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" python get-pip.py
|
或者yum安装,然后升级
1 2
| yum install -y python-pip pip install --upgrade pip
|
1
| yum install python-devel
|
numpy
1 2 3 4 5
| pip install numpy
pip install matplotlib yum install tkinter pip install scipy
|
matplotlib
scipy
是非必须的,但使用opencv python 肯定用的着,所以建议一起安装好。 tkinter
是 matplotlib
的依赖
Opencv3.2 源码安装
工作目录为 ~
, 按照你的喜爱调整,记得下面的目录都要调整
获取源码
1 2 3 4
| cd ~ git clone https://github.com/opencv/opencv.git cd opencv git checkout 3.2.0
|
- opencv_contrib
从 opencv 3.0 开始, opencv_contrib 单独发布, 这里有很多有意思的功能
1 2 3 4
| cd ~ git clone https://github.com/opencv/opencv_contrib.git cd opencv_contrib git checkout 3.2.0
|
编译安装
编译目录
1 2 3
| cd ~/opencv mkdir build cd build
|
cmake
1 2 3 4 5 6 7
| cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \ -D INSTALL_C_EXAMPLES=OFF \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D BUILD_EXAMPLES=ON \ -D BUILD_OPENCV_PYTHON2=ON ..
|
特保注意:
make
查看输出日志
1 2 3
| Linking CXX shared module ../../lib/cv2.so 。。。 Built target opencv_python2
|
基本代表 opencv python make
成功, 如果没有, 使用 cmake-gui ..
重新 make
一次
make install
检查 /usr/local/lib/python2.7/site-packages
目录下 是否已经成功安装 cv2.so
链接给python
1 2
| cd /usr/lib64/python2.7/site-packages ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so
|
测试opencv-python
1 2 3 4
| python >>>import cv2 >>>cv2.__version__ 3.2.0'
|
congratulation!!!