在ubuntu14.04系统上安装OpenCV3.2.0
[环境要求]
GCC 4.4.x or later
CMake 2.8.7 or higher
Git (if failed, you can replace it with git-core)
GTK+2.x or higher, including headers (libgtk2.0-dev)
pkg-config
Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
[optional] libtbb2 libtbb-dev
[optional] libdc1394 2.x
[optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
[optional] CUDA Toolkit 6.5 or higher
【环境准备】
根据环境要求,安装所需功能包,以下命令若出现安装失败(特别是git),请先删除,后面独立安装即可。
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
【源码获取】
若是要获取最新稳定版本,请到OpenCV官网获取。本文以当前最新开发版本(git)OpenCV为例说明安装过程。
cd ~/work/salg_git/SALG (这是我的工作路径,阅读者请根据自己需要创建相应工作路径)
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git(这个库,若没用到里面的功能,可以不下载)
【源码编译】
本文采用OpenCV官方建议的CMake编译源码。
1. 切换到opencv路径
cd ~/work/salg_git/SALG/opencv
2. 创建编译目录
mkdir build(不建议直接在源码目录opencv下编译)
3. 切换到编译目录
cd build
4. 配置生成Makefile
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
5. 编译
make -j7 (-j7表示希望用7个线程并行编译,提高编译速度)
6. 安装
sudo make install
备注:安装后,OpenCV相关库安装在/usr/local/lib, 头文件在/usr/local/include/opencv2
7. 执行示例程序
这里以人脸侦测为例,运行samples目录中的cpp-example-facedect程序侦测图片/视频中的人脸/鼻子/眼睛
./build/bin/cpp-example-facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_eye_tree_eyeglasses.xml" --scale=1.5 http://192.168.1.60:8800/stream/video/h264?resolution=VGA