提前申明一下,我搭建的环境版本是2.4.9(很老的版了,但是基本功能都有)源码安装。
1.安装依赖文件
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config
sudo apt-get install python-dev python-numpy
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev
2.下载源码文件
1.在你的家目录下新建一个opencv(这只不过是名字而已 ,你爱叫啥叫啥名,不影响,这里用opencv代替)文件夹
2.接着下载opencv源码
下载可以使用树莓派自带的游览器直接下载,下载好移动到opencv文件夹中
3.解压 upzip opencv-2.4.9.zip
3.编译
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo ldconfig
在cmake过程中问题是会有的,但解决的方法也会有的!
第一种报错信息:
/home/hiscene/Downloads/opencv-2.4.8.3/modules/contrib/src/chamfermatching.cpp:969:30: error: the compiler can assume that the address of ‘annotate_img’ will never be NULL [-Werror=address]
if (&annotate_img!=NULL) {
^
/home/hiscene/Downloads/opencv-2.4.8.3/modules/contrib/src/chamfermatching.cpp:1016:34: error: the compiler can assume that the address of ‘annotate_img’ will never be NULL [-Werror=address]
if (&annotate_img!=NULL) {
^
/home/hiscene/Downloads/opencv-2.4.8.3/modules/contrib/src/chamfermatching.cpp: In member function ‘cv::ChamferMatcher::Match* cv::ChamferMatcher::Matching::localChamferDistance(cv::Point, cv::Mat&, cv::Mat&, cv::ChamferMatcher::Template*, float)’:
/home/hiscene/Downloads/opencv-2.4.8.3/modules/contrib/src/chamfermatching.cpp:1111:25: error: the compiler can assume that the address of ‘orientation_img’ will never be NULL [-Werror=address]
AM_CFLAGS = -Wall -g $(MATCHBOX_PANEL_CFLAGS) \
-I$(top_srcdir) -I$(top_builddir) -Werror
说是把 -Werror 去掉
但是opencv是依赖cmake编译的,于是根据报错信息进入到了相应的目录,在flags.make文件里面找到了-Werror=address,将其去掉,然后保存,重新编译后就成功了。
flags.make文件可以在文件管理中直接查找。
第二种报错信息:
usr/include/c++/6/cstdlib:75:25: fatal error: stdlib.h: 没有那个文件或目录
cmake -D CMAKE_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local.. -DENABLE_PRECOMPILED_HEADERS=OFF
这个是我在编译的中遇到的问题,若有什么不妥的地方,欢迎大家指出!
在后面我会贴出我用的代码,以供大家参考。
要是大家在下载安装文件或者 安装依赖的时候下载速度很慢,这里建议大家可以更换apt的源(也就是软件源),这里给出我的软件源 供大家参考:
1 deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib
2 deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ jessie main non-free contrib
这个路径在:/etc/apt 修改sources.list文件 (需要加root权限或者直接sudo )
保存完了,记得更新一下:
sudo apt-get update
sudo apt-get -y uograde
上面第一个 阿里的云平台,第二个是清华大学的镜像站,下载速度杠杠的 。
使用python的话,若是大家使用pip来管理你的包文件的话,建议可以替换pip的源,这里也给出我的pip源,供大家参考:
1 [global]
2 index-url = https://pypi.tuna.tsinghua.edu.cn/simple
3 [install]
4 trusted-host=mirrors.aliyun.com
这个路径在:/home/pi/.pip(.pip文件夹) 修改pip.conf文件(没有的还直接新建就行)
这里同样,第一个是清华大学的,第二个是阿里的
愿你们,创新不要因为“速度”而尴尬!!!