1.更新
$ sudo apt-get update
$ sudo apt-get upgrade
2.安装开发工具
$ sudo apt-get install build-essential cmake pkg-config
3.安装Image I/O
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
4.安装video I/O
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
5.安装GTK
$ sudo apt-get install libgtk2.0-dev
6.安装gfortran 一个新的矩阵运算框架
$ sudo apt-get install libatlas-base-dev gfortran
7.安装python开发框架
$ sudo apt-get install python2.7-dev python3-dev
二。下载opencv
$ cd ~
$ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.1.0.zip
$ unzip opencv.zip
$ wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip
$ unzip opencv_contrib.zip
三。安装python
1.安装pip
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
2.安装虚拟环境
$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/.cache/pip
3.配置虚拟环境
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
$ echo -e “\n# virtualenv and virtualenvwrapper” >> ~/.profile
$ echo “export WORKON_HOME=$HOME/.virtualenvs” >> ~/.profile
$ echo “source /usr/local/bin/virtualenvwrapper.sh” >> ~/.profile
source ~/.profile
4.建立虚拟环境
mkvirtualenv cv -p python2
python2
或
mkvirtualenv cv -p python3
python3
以下操作都在虚拟环境中进行
5安装NumPy
pip install numpy
6.编译安装opencv
$ cd ~/opencv-3.1.0/
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \
-D BUILD_EXAMPLES=ON ..
$ make -j4
$ sudo make install
$ sudo ldconfig
for Python 2.7
$ cd ~/.virtualenvs/cv/lib/python2.7/site-packages/
$ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so
for Python 3.4
$ cd /usr/local/lib/python3.4/site-packages/
$ sudo mv cv2.cpython-34m.so cv2.so
$ cd ~/.virtualenvs/cv/lib/python3.4/site-packages/
$ ln -s /usr/local/lib/python3.4/site-packages/cv2.so cv2.so
7.测试
$ source ~/.profile
$ workon cv
$ python
>>> import cv2
>>> cv2.__version__
‘3.1.0’
>>>
8.删除源码,节省空间
$ rm -rf opencv-3.1.0 opencv_contrib-3.1.0
你好,我安装到make -j4显示安装失败,你知道是为什么吗
具体什么错误呢? 一般将提示的英文在Google里搜索一下 都会找到答案