树莓派3安装openCV

本人准备用树莓派+python+openCV实现一个家庭监控的装置 ,在此先介绍如何将opencv安装到 树莓派上,以及用opencv库对树莓派实现简单的应用。在此参考了如下链接的资料:http://www.pyimagesearch.com/2015/02/23/install-opencv-and-python-on-your-raspberry-pi-2-and-b/


第一步 :首先更新树莓派的系统 ,使用如下命令:

stall OpenCV and Python your Raspberry Pi 2 and B+
Shell
1
2
3
$ sudo apt - get update
$ sudo apt - get upgrade
$ sudo rpi - update

第二步:安装必要的开发工具和包

enCV and Python your Raspberry Pi 2 and B+
Shell
1
$ sudo apt - get install build - essential cmake pkg - config

第三步: 一些图片格式的包JPEG, PNG, TIFF, etc

enCV and Python your Raspberry Pi 2 and B+
Shell
1
$ sudo apt - get install libjpeg8 - dev libtiff4 - dev libjasper - dev libpng12 - dev

第四步:安装GTK开发库,使用来建立GUI,opencv可以使用期在屏幕上显示我们的图像

enCV and Python your Raspberry Pi 2 and B+
Shell
1
$ sudo apt - get install libjpeg8 - dev libtiff4 - dev libjasper - dev libpng12 - dev

第五步:安装必要的视频包

$ sudo apt - get install libavcodec - dev libavformat - dev libswscale - dev libv4l - dev

第六步:安装用于在OpenCV中优化各种操作的库

sudo apt - get install libatlas - base - dev gfortran

第七步:安装pip

nstall OpenCV and Python your Raspberry Pi 2 and B+
Shell
1
2
$ wget https : / / bootstrap .pypa .io / get - pip .py
$ sudo python get - pip .py

第八步:

virtualenv   and  virtualenvwrapper
Install OpenCV and Python your Raspberry Pi 2 and B+
Shell
1
2
$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm - rf ~ / .cache / pip
更新我们的文件 ~ / . profile

Install OpenCV and Python your Raspberry Pi 2 and B+
Shell
1
2
3
# virtualenv and virtualenvwrapper
export WORKON_HOME = $HOME / .virtualenvs
source / usr / local / bin / virtualenvwrapper .sh

Reload your .profile  file:

Create your computer vision virtual environment:

第九步:如果没有python2.7的同学请安装
nstall OpenCV and Python your Raspberry Pi 2 and B+
Shell
1
$ sudo apt - get install python2 . 7 - dev


我们还需要安装Python绑定NumPy从OpenCV图像表现为多维NumPy数组
$ pip install numpy
第十步:下载Opencv并解压

tall OpenCV and Python your Raspberry Pi 2 and B+
Shell
1
2
3
$ wget - O opencv - 2.4.10.zip http : / / sourceforge .net / projects / opencvlibrary / files / opencv - unix / 2.4.10 / opencv - 2.4.10.zip / download
$ unzip opencv - 2.4.10.zip
$ cd opencv - 2.4.10
编译opencv:

编译的时候可能需要几个小时,所以请耐心的等待。编译完成后,在按下面两步完成Opencv的安装

tall OpenCV and Python your Raspberry Pi 2 and B+
Shell
1
2
$ sudo make install
$ sudo ldconfig

第11步, 如果安装正确了的话,openCV 应该是被安装到了下面的目录下
/usr/local/lib/python2.7/site-packages

但为了利用OpenCV在CV的虚拟环境,我们首先需要链接Opencv到我们的site-packages目录

2
3
$ 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

最后我们可以做一个测试

2
3
4
5
$ workon cv
$ python
>>> import cv2
>>> cv2 .__version__
'2.4.10'
这样我们成功的在树莓派上安装了opencv

$ sudo apt - get install libavcodec - dev libavformat - dev libswscale - dev libv4l - dev
2
3
$ 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
2
3
4
5
$ workon cv
$ python
>>> import cv2
>>> cv2 .__version__
'2.4.10'

你可能感兴趣的:(树莓派3B+,emmc)