参考网址:
1 opencv 官网:http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html?highlight=install
2 http://www.ozbotz.org/opencv-installation-2-3-1/
3 http://anuruddhapremalal.blogspot.com/2013/10/install-opencv-246-on-ubuntu.html
4 http://www.pcduino.org/forum.php?mod=viewthread&tid=314
把之前安装OpenCV的经验贴出来。以下是主要的步骤及故障排除
一,安装如下软件或者依赖包
GCC 4.4.x 或者更高版本. 输入命令:
sudo apt-get install build-essential
Cmake 2.6 或者更高版本 :
sudo apt-get install cmake
Git :
sudo apt-get install git
GTK+2.x or higher, including headers (libgtk2.0-dev) :
sudo apt-get install libgtk2.0-dev
libdc1394 2.x或者更高版本
sudo apt-get install libdc1394-22-dev
pkgconfig :
sudo apt-get install pkgconfig
Python 2.6 和 Numpy 1.5 或更高版本的packages :
sudo apt-get install python
sudo apt-get install python-numpy
ps:若pkgconfig无法在终端安装:
下载地址:http://pkgconfig.freedesktop.org/releases/
解压后在目录下执行如下命令:
./configure --with-internal-glib
make
sudo make install
二,Cmake
解压下载好的opencv 2.4.6的压缩包
cd OpenCV-2.4.6.1/
mkdir build
cd build
cmake ..
三,make
make
sudo make install
四.更新动态链接库和配置文件
sudo gedit /etc/ld.so.conf.d/opencv.conf
#添加opencv lib库所在路径:/usr/local/lib ,保存
sudo ldconfig
#进行配置
sudo gedit /etc/bash.bashrc
#
更新配置文件:
在末尾添加:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
五.测试Sample
进入到sample/c目录下:
./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=.5 ./lena.jpg
输出人脸检测结果,ok。
六、快速查询手册
不少人在学习Opencv知道使用官方厚厚的tutorials,其实有个2页的官方查询手册也蛮不错的。值得推荐下:
http://docs.opencv.org/trunk/opencv_cheatsheet.pdf
卸载:
make uninstall
故障
1.测试例子时报错:
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /home/liuwei/SOFT/opencv-2.4.6.1/modules/highgui/src/window.cpp, line 483
terminate called after throwing an instance of 'cv::Exception'
原因(1):GTK+ 2.x 未安装或者是在安装opencv 之后才安装。
解决:卸载opencv,重新Cmake……
原因(2):GTK+ 2.x已安装,但不能被识别
cmake opencv 时会有提示:
checking for module 'gtk+-2.0'
package 'gtk+-2.0' not found
GUI: QT 4.x: NO GTK+ 2.x: NO GThread : NO
解决:修改环境变量,更新配置文件:sudo gedit /etc/bash.bashrc找到gtk+-2.0.pc 所在路径,将路径添加到环境变量PKG_CONFIG_PATH中。如,若gtk+-2.0.pc处在/usr/lib/x86_64-linux-gnu/pkgconfig下,则:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/x86_64-linux-gnu/pkgconfig
export PKG_CONFIG_PATH
Gtk与Qt编译环境安装与配置
http://wiki.ubuntu.org.cn/Gtk与Qt编译环境安装与配置