compile opencv in centos

来源:互联网 发布:网络品牌策划 编辑:程序博客网 时间:2024/06/05 01:50

(1) 源
cat /etc/centos-release
sudo yum -y update
yum list available opencv*

(2)工具
sudo yum groupinstall ‘Development Tools’
sudo yum install cmake git pkgconfig

(3)一些依赖
sudo yum install libpng-devel libjpeg-turbo-devel jasper-devel openexr-devel libtiff-devel libwebp-devel

sudo yum install libdc1394-devel libv4l-devel gstreamer-plugins-base-devel
sudo yum install gtk2-devel

(4)
sudo yum install tbb-devel eigen3-devel

(5)python pip
$ curl “https://bootstrap.pypa.io/get-pip.py” -o “get-pip.py”
$ sudo python get-pip.py

(6)python分割环境
sudopipinstallvirtualenvvirtualenvwrapper sudo rm -rf ~/.cache/pip

~/.bashrc by adding these two lines to the file.
exportWORKONHOME=HOME/.virtualenvs
$ source /usr/bin/virtualenvwrapper.sh

(7) 虚拟环境
Now is the time to create a virtual environment, let’s call it cv

$ mkvirtualenv cv

You will notice a (cv) indicator at your command line. It means that we are in the virtual environment where we will be installing OpenCV. You can exit this environment by typing

$ deactivate

if you are not in the cv virtual environment, just type in

$ workon cv

(8)python环境
$ python –version

and you should see Python 2.7 version.
Install Python 2.7 development tools

$ sudo yum install python-devel

Install NumPy since OpenCV is using its arrays (and it is a very powerful package as well)

$ sudo pip install numpy

(9)install opencv
cd  git clone https://github.com/Itseez/opencv.git
cdopencv git checkout 3.1.0

cd  git clone https://github.com/Itseez/opencv_contrib.git
cdopencvcontrib git checkout 3.1.0

cd /opencv mkdir build
$ cd build

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 ..
sudo make
sudomakeinstall sudo ldconfig

Check the following folder and see if OpenCV is installed

/usr/local/lib/python2.7/site-packages

(10) 虚拟环境安装
Now is the time to create a symbolic link to OpenCV library into the site-packages directory of the cv virtual environment:

cd /.virtualenvs/cv/lib/python2.7/sitepackages/ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so
Your installation is successfuly completed. You can confirm it by going into the virtual environment and importing OpenCV library.

workoncv python

import cv2
cv2.version
3.1.0’