如何在树莓派中树莓派安装opencvv,如何运行代码

下次自动登录
现在的位置:
& 综合 & 正文
在树莓派上安装OpenCV视觉库
OpenCV is a suite of powerful computer vision tools. Here is a quick overview of how I installed
OpenCV on my Raspberry Pi with debian6-19-04-2012.
is based on the official OpenCV Installation Guide on Debian and Ubuntu.
Before you begin, make sure you have expanded your SD card to allow for the install of OpenCV. Its a big package with lots of dependencies. You can follow my instructions here.
Once you have expanded the SD card, open up a terminal and install the following packages:
sudo apt-get -y install build-essential cmake cmake-qt-gui pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev zlib1g-dbg zlib1g zlib1g-dev pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools
sudo apt-get -y install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs ffmpeg libavcodec-dev libavcodec53 libavformat53 libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils swig libv4l-0 libv4l-dev python-numpy libpython2.6 python-dev python2.6-dev libgtk2.0-dev pkg-config
There are some dependency issues with the order of the install, mostly with regard to libjpeg issues, so be sure to install in this order. You will see some broken package
errors if you attempt to install all the dependencies in one step.
Next, pull down the source files for OpenCV using wget:
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2
Once finished downloading, extract the archive, remove the no longer needed archive (to save space),
change directory to the top of the source tree, make a directory for the build, and change into it:
ar -xvjpf OpenCV-2.3.1a.tar.bz2
rm OpenCV-2.3.1a.tar.bz2
cd OpenCV-2.3.1/
mkdir build
Next, you will need to configure the build using cmake. If you aren’t sure about what options you
want/need or are unfamiliar with cmake, this line will create a standard configuration:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..
Alternatively, you can configure the build using a GUI interface. This can be helpful
to build with support for additional OpenCV features. To use the cmake GUI, run:
cmake-gui ..
In the cmake GUI, click ‘configure’ to pre-populate the build options. Select or remove
any desired features, then click ‘configure’ again, check the output and ensure that there are not any modules that cmake cannot find. If everything looks good, click ‘generate’ to create the makefiles, then close cmake-gui. Now we are ready to start the build!
To compile, run make, then install with make install:
sudo make install
As you can see from the image, this will take a LONG time… over four and a half hours to compile!
we need to make a few configurations for OpenCV. First, open the opencv.conf file with the following code:
sudo nano /etc/ld.so.conf.d/opencv.conf
Add the following line at the end of the file(it may be an empty file, that is ok)
and then save it:
/usr/local/lib
Then edit the system-wide bashrc file:
sudo nano /etc/bash.bashrc
Add the following new lines to the end of the file:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH
Now that everything is installed and configured, on to the demos!
The C demos are here:
cd ~/opencv/OpenCV-2.3.1/build/bin
C demos in build/bin demos worth checking out (that don’t require a webcam):
convexhull
The python demos are located in samples/python:
cd ~/opencv/OpenCV-2.3.1/build/bin
These demos also don’t require a webcam:
python ./minarea.py
python ./delaunay.py
python ./drawing.py
原文地址:
&&&&推荐文章:
【上篇】【下篇】在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。
标签:至少1个,最多5个
因为树莓派的 cpu 和内存大小的限制,在树莓派上跑 IDE 不太可能,对于简单的程序,我们可以通过
bashgcc -o main main.cpp
完成小程序的编译过程.然而我们如果要开发像车牌识别,人脸识别这样的基于 opencv 的大型程序,手写 makefile 不太可能.曾经考虑过使用 cmake.最后还是感觉 cmakelist.txt 太难写了,考虑到 Qt的 qmake 比较好用,Qt又有跨平台的优势,所以还是选择了使用 Qt了.
树莓派上的环境搭建
bashsudo apt-get install qt4-dev-tools
#安装 Qt 开发环境
sudo apt-get install libopencv-dev
#安装 opencv
PC 机上开发环境
到中科大开源镜像站下载就行了,注意与自己的visual studio版本一致
在 PC 机上开发好后修改 pro 文件就可以了
INCLUDEPATH += /usr/include \
INCLUDEPATH += /usr/include/opencv
LIBS += -L/usr/lib \
-lopencv_calib3d \
-lopencv_contrib \
-lopencv_core \
-lopencv_features2d \
-lopencv_flann \
-lopencv_gpu \
-lopencv_highgui \
-lopencv_imgproc \
-lopencv_legacy \
-lopencv_ml \
-lopencv_objdetect \
-lopencv_video
#include &iostream&
#include &opencv2/opencv.hpp&
int main(int argc, char **argv)
Mat im = imread(argv[1]);
cvtColor(im, gray, CV_RGB2GRAY);
imwrite ("gray.jpg",gray);
树莓派下编译
bashqmake *.pro
#生成 makefile
./Rpi 1.jpg #运行 生成灰度图像 gray.jpg
这样就可以完成 PC 机上开发大型 opencv 图像处理程序,最小修改代码,方便移植到开发板上了.
0 收藏&&|&&2
你可能感兴趣的文章
1 收藏,4k
1 收藏,2.4k
15 收藏,1.8k
本作品采用 署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可
分享到微博?
我要该,理由是:
在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。15:46 提问
树莓派opencv调用树莓派摄像头
在树莓派3上安装了opencv,用opencv去掉用usb接上的摄像头可以,但是不能获取树莓派的标准摄像头?应该怎么去设置
按赞数排序
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐[原创]在Raspberry Pi(树莓派)上用OpenCV来操纵摄像头拍照/Use OpenCV on Raspberry Pi to Controll a Webcam to Take Photos – 编码无悔 /
Intent & Focused【教程】树莓派安装OS之后的初始配置,以安装OpenCV 3.1.0为例 - 简书
【教程】树莓派安装OS之后的初始配置,以安装OpenCV 3.1.0为例
从下载树莓派的映像安装OS之后,还需要通过terminal安装一些基本的库之后才能满足开发需求。
比如在Raspberry pi上配置OpenCV的库,这里以为例进行说明。
第一次启动树莓派后的安装操作
首先启动树莓派,通过SSH或者直接给树莓派连接显示器和键鼠打开一个terminal。SSH客户端推荐或,文件传输推荐。
更新树莓派:
sudo apt-get update
sudo apt-get upgrade
然后重启树莓派:
sudo reboot
安装基本的依赖项:
sudo apt-get install build-essential cmake pkg-config
安装和图像相关的库:
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
安装基本的IO库:
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
安装highgui相关的依赖库:
sudo apt-get install libgtk2.0-dev
安装opencv进阶依赖库,操作矩阵等:
sudo apt-get install libatlas-base-dev gfortran
由于中使用python并且建立了代码的虚拟环境,这里略去python和虚拟环境的安装。
下载OpenCV 3.1.0和OpenCV_contrib库:
对于新手,可以先进入download目录cd ~/Downlaod再下载,如果直接输入命令会下载到你termianl的当前路径下。
下载OpenCV 3.1.0:
wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.1.0.zip
解压OpenCV 3.1.0:
unzip opencv.zip
下载OpenCV_contrib库:
wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip
解压OpenCV_contrib库:
unzip opencv_contrib.zip
编译和安装OpenCV 3.1.0
步骤类似于在Linux上的操作,使用Makefile来完成编译。关于Makefile,新手可以去查找一下相关的使用,这样方便理解linux上开源库的使用和如何在windows上用visual studio来编译需要的开源库。
进入opencv3.1.0目录:
cd opencv-3.1.0/
新建build文件夹:
mkdir build
进入build文件夹:
配置cmake(这一步直接粘贴所有行到你的terminal即可):
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 ..
sudo make install
把OpenCV生成的动态链接库加入树莓派目录:
sudo ldconfig
到这里就完成了树莓派的配置和OpenCV 3.1.0的安装。
所书教程如有错误、不当之处,欢迎批评、指正 —— 曦沉
玩转树莓派 18:59 毕业论文 基于微型计算机的人脸识别门禁系统设计 1. 课题意义及目标 随科技的不断发展,安全性的要求也不断提高,IC卡等传统身份识别工具已不能满足社会需求。所以从通用性、安全性、成熟性和造价性等多方面综合考虑,研究新的识别工具是一...
Opencv3.1 & Opencv3.2 第一种方式(适用于Linux):一、准备工作1、仓库的更新:sudo apt-get update2、python必要的插件(-y指的是安装默认选择yes,下同):sudo apt-get install python3-setu...
树莓派安装opencv的教程层出不穷,但是能用的很少。我这个教程是亲自安装成功的。 我之前安装过好几次opencv2.49都失败了,唯独这个opencv3.1成功了。 下面开始安装吧 1.准备 sudo apt-get install build-essential git...
第一次尝试,太天真 一,更新ubuntu软件源 sudo apt-get update 二,opencv安装 sudo apt-get install libcv-dev ps:删除配置文件 cd /var/cache/apt/archivessudo apt-get cl...
虽说MXNet安装过程相对简单,但是实际在操作的时候也遇到了不少坑,在这里简单记录一下。 我用的显卡型号是GeForce GTX 1060。显卡的驱动安装和CUDA以及CUDNN的配置因为之前已经搞定了,这里就不赘述(整个过程也是踩遍了各种坑坑洼洼,有空再另写一篇)。CUD...
今天在家乡以外的一个城市里练车,准备考驾照。这对我来说是一件没有兴趣的事情,不了解不喜欢,只是跟随着大家的脚步按部就班。有人在提醒你,是考驾照的时候了,于是我们就开始练习学习;有人在告诉你,是结婚生子的时候了,于是我们也开始加入到了相亲的阵营中。
在我的家庭中,没有...
此刻,我拿着手机,想着给2015年最后的自己留点什么,想了想,还是说说这几年我的生活吧!不求安慰,只想说说这些压在心里的事。 时间得从2010年开始,那年我17,一个17岁的少年,在大家的心中应该是在挥霍青春的,而我,因为上天眷顾,早早出了社会。日,家里发...
被薛之谦的一半默默洗脑,听着不痛不痒的歌词,说实话其实并没有太大感慨,或许我本身的性格就是这么冷情,似乎没有什么能过多牵动我的心,到如今也没有谁说是真正走进心里,心痛是什么感觉,我不知道,有时候回忆是一把刀让人想难过,可是回头细细的想,说到底那些曾经的种种,其实并没有什么可...
使用“极速读书法”的学习历程小记。
这是在社群里看到有小伙伴提起Xdite老师组织发起的极速读书会,心生好奇,于是查到了“极速读书法”的使用步骤: Step1:找出你最想问这本书的一个问题每次读书的时候,就写上书名你最想要在书中得到的一个解答你提出这个问题的动机St...
思念是一片海 淹没红尘万丈 思念是一首歌 唱尽悲欢离合 思念是一首诗 书写人世百态 思念是星星 数不尽的酸甜苦辣 今夜,我将思念寄明月 幽幽月华随风走 你看见的是美景 看不见的是落寞 倚栏而望是思 并肩而立却是念 我们把酒言欢 无关风月,只有哥俩

我要回帖

更多关于 树莓派运行opencv 的文章

 

随机推荐