1.下载源码 opencv,选择2.4.9版本,http://opencv.org/downloads.html
2.安装依赖项,等待三个小时
sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev
最后若提示
E: 无法下载 http://archive.ubuntu.com/ubuntu/pool/main/l/latex-beamer/latex-beamer_3.24-1_all.deb 连接失败 [IP: 91.189.88.152 80]
E: 无法下载 http://archive.ubuntu.com/ubuntu/pool/main/t/texlive-base/texlive-luatex_2013.20140215-1_all.deb 连接失败 [IP: 91.189.88.149 80]
E: 有几个软件包无法下载,您可以运行 apt-get update 或者加上 --fix-missing 的选项再试试?
没有关系
3.编译opencv
cd opencv-2.4.9
mkdir build
cd build
cmake ..
make
sudo make install
4.更改/etc/ld.so.conf.d/opencv.conf文件
cd
sudo vi /etc/ld.so.conf.d/opencv.conf
打开后是个空文件(若不是空文件shift+g跳到页面最低端),i,把/usr/local/lib 加进去.(ctrl+shift+v就行了)
sudo ldconfig
5.更改/etc/bash.bashrc文件
cd /etc
sudo cp bash.bashrc bashcopy.bak
备份
sudo vi /etc/bash.bashrc
在末尾加入
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
6.测试
将opencv源码包下的example/c拷贝到opencv文件夹里
cd opencv-2.4.9/c
./build_all.sh
./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg
若出现
说明编译成功