最近因为项目需要,要在pcduino上,实现图像识别算法,面临的第一个问题就是怎么安装opencv。
昨天,编译的三遍也没弄好。今天有幸弄好了。
主要参考:
1.http://blog.csdn.net/lqhbupt/article/details/7913513
2.http://www.oschina.net/question/1425530_139916
3.http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation
1)在安装OpenCV前需要安装的软件包有
GCC4.4.X or later,可通过命令sudo apt-get install build-essential安装
CMake2.6 or later
SVN客户端
GTK+2.Xor higher, including headers(libgtk2.0-dev)
pkgconfig
Python2.6 or later and Numpy 1.5 or later with developerpackages(python-dev, python-numpy)
ffmpegor libav development packages: libavcodec-dev, libavformat-dev,libswsacle-dev
[可选]libdc13942.x
[可选]libjpeg-dev,libpng-dev, libtiff-dev, libjasper-dev
2)下载最新版OpenCV
打开网页:http://sourceforge.net/projects/opencvlibrary
下载安装包OpenCV-2.4.0.tar.bz2
sudo tar jxvf OpenCV-2.4.0.tar.bz2 -C /usr/local/
cd /usr/local/
sudo mv OpenCV-2.4.0 opencv
cd opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
这里最好把Opencv下载到u盘里,然后再解压到/usr/local/文件夹下。这样节省空间。
3、开始编译
make
make install
3)安装后的配置
添加库的路径
sudo gedit /etc/ld.so.conf.d/opencv.conf
添加内容
/usr/local/lib
在终端输入命令
sudo ldconfig
设置环境变量
sudo gedit /etc/bash.bashrc
在文件最后加入以下两行并保存:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
此时重启Ubuntu或重新登录账户,使得OpenCV安装生效。
4)测试OpenCV自带例程
编译程序:
cd /usr/local/opencv/samples/c
chmod +x build_all.sh
./build_all.sh
运行程序:
./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg
运行结果如下:
运行程序:
./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_eye.xml" --scale=1.5 lena.jpg
运行结果如下:
运行程序:
python /usr/local/opencv/samples/python2/turing.py
程序结果如下: