注意只适用于Python2, Opencv3, Raspberry3, Ubuntu14, debian jessie
$ sudo apt-get update
$ sudo apt-get upgrade
# ubuntu 不需要
$ sudo rpi-update
$ sudo reboot
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
主要用于屏幕显示图像,并且构建简单的GUI interfaces
$ sudo apt-get install libgtk2.0-dev
$ sudo apt-get install libatlas-base-dev gfortran
# 安装zsh
$ apt install zsh
# 安装oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# 或者
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
sudo apt-get install git
# 常用的命令都设置alias,尽量少敲键盘
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.st status
# 很好看地显示git log
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen (%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
# 设置用户信息
git config --global user.name "Mousse"
git config --global user.email [email protected]
# 缺省使用颜色显示
git config --global color.ui true
sudo apt-get install vim
git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim_runtime
sh ~/.vim_runtime/install_awesome_vimrc.sh
perl: warning: Please check that your locale settings: /usr/local/webserver/php/bin/phpize Configur
$ echo "export LC_ALL=C" >> /root/.bashrc
$ source /root/.bashrc
# 或者
$ echo "export LC_ALL=C" >> /root/.zshrc
$ source /root/.zshrc
# 安装python2 ,python3头文件和OpenCV绑定
sudo apt-get install python2.7-dev python3-dev
# 安装pip依赖关系
sudo apt-get install build-essential libssl-dev libevent-dev libjpeg-dev libxml2-dev libxslt-dev
sudo apt-get install python-pip
sudo pip install virtualenv virtualenvwrapper
$ vi ~/.profile 或者 vi ~/.zshrc
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
$ source ~/.zshrc
# python2
$ mkvirtualenv cv
# python3
$ mkvirtualenv cv -p python3
$ mkdir opencv3
$ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.3.1.zip
$ unzip opencv.zip
### 下载opencv_contrib(主要使用SIFT和SURF)
和opencv版本必须统一
$ wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.3.1.zip
$ unzip opencv_contrib.zip
$ pip install numpy -i https://pypi.douban.com/simple/
$ apt-get install cmake
设置 ENABLE_NEON=ON , ENABLE_VFPV3=ON 是为了提高树莓派的运算能力
$ cd ~/opencv/opencv-3.3.1
$ mkdir bulid
$ cd bulid
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib-3.3.1/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_EXAMPLES=OFF ..
$ cd ~/opencv/opencv-3.3.1
$ mkdir bulid
$ cd bulid
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON\
-D OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib-3.3.1/modules \
-D BUILD_EXAMPLES=ON ..
注意: 编译时候在 tiny-dnn: Download: v1.0.0a3.tar.gz 时候会很慢很慢,等一下就可以了
opencv3.3b编译会消耗大量内存,树莓派内存太小,所以只有增大swap来完成
$vi /etc/dphys-swapfile
# 找到CONF_SWAPSIZE=100改为1024
# set size to absolute value, leaving empty (default) then uses computed value
# you most likely don't want this, unless you have an special disk situation
CONF_SWAPSIZE=1024
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
编译超级慢,1个半小时吧,一定要增大swap要不然编译会挂起
$ make -j4
$ sudo make install
$ sudo ldconfig
$ cd ~/.virtualenvs/cv/lib/python2.7/site-packages/
$ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so
$ source ~/.zshrc
$ workon cv
$ python
>>> import cv2
>>> cv2.__version__
'3.3.1'