树莓派python3下编译安装opencv

opencv安装耗时长配置复杂,为保证一次就安装成功,请做好以下准备:
1. SD卡可用空间>4GB
2. 保证电流足够大,去掉多余的外设,2A以上电源供电
3. 保证散热良好,我就是因为CPU过热自动关机一次 ,好在make命令可以继续任务

依赖库

sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran

下载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

虚拟环境

sudo pip3 install virtualenv virtualenvwrapper
sudo rm -rf ~/.cache/pip

echo -e "\n# virtualenv and virtualenvwrapper" >> ~/.profileecho
"export WORKON_HOME=$HOME/.virtualenvs" >> ~/.profileecho
"source /usr/local/bin/virtualenvwrapper.sh" >> ~/.profilesource 
~/.profile

mkvirtualenv cv -p python3
source ~/.profile 
workon cv
pip install numpy 

编译(虚拟环境中)

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D ENABLE_PRECOMPILED_HEADERS=OFF \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules\
    -D BUILD_EXAMPLES=ON ..
make
sudo make install
sudo ldconfig
waiting few hours.....

链接包到虚拟环境

Python 2.7
cd ~/.virtualenvs/cv/lib/python2.7/site-packages/
ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so
ln -s /usr/local/lib/python2.7/site-packages/cv.py cv.py
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

验证

workon cv
python3 -m cv

花了好几个小时、半瓶盖的水才装上。。水冷散热Auto版(笑)

_ 参考资料
https://www.jianshu.com/p/785fded60190
http://blog.csdn.net/layallan/article/details/78328943
http://blog.csdn.net/xazzh/article/details/52885037

Install guide: Raspberry Pi 3 + Raspbian Jessie + OpenCV 3


_

2 条评论

[/0o0] [..^v^..] [0_0] [T.T] [=3-❤] [❤.❤] [^v^] [-.0] [!- -] [=x=] [→_→] [><] 更多 »
昵称
  1. S1NH Microsoft Edge 14 Microsoft Edge 14 Windows 10 Windows 10

    水冷散热牛逼

    1. 鸽子 鸽子 Google Chrome 64 Google Chrome 64 Windows 10 Windows 10

      又升级成了水冷auto版2333