运行平台:Ubuntu14.04
OpenCV版本:OpenCV2.4.13
转载请注明作者和出处:http://www.jb51.cc/article/p-qhdexlja-da.html
一、安装OpenCV2.4.13
1.使用wget下载OpenCV源码
url : https://github.com/Itseez/opencv/archive/2.4.13.zip
sudo apt-get install wget
sudo wget https://github.com/Itseez/opencv/archive/2.4.13.zip
2.解压ZIP源码文件
sudo apt-get install unzip
sudo unzip opencv-2.4.13.zip
3.进入源码目录,创建release目录
cd opencv-2.4.13
mkdir release
4.安装依赖库
sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev
5. 进入release目录,安装OpenCV时,所有的文件都会被放到这个release目录下
cd release
6. cmake编译OpenCV源码,安装所有的lib文件都会被安装到/usr/local/opencv2.4.13目录下
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv2.4.13 ..
7.安装
sudo make install -j4
二、配置pkg-config(可选)
1.创建pkgconfig目录
mkdir /usr/local/pkgconfig
2.拷贝opencv.pc文件到pkgconfig目录
cp /usr/local/opencv2.4.13/lib/pkgconfig/opencv.pc /usr/local/pkgconfig/opencv2.4.pc
3.以管理员权限用vim打开bash
sudo vim ~/.bashrc
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/pkgconfig
export PKG_CONFIG_PATH
source ~/.bashrc
6.测试pkgconfig
pkg-config --libs opencv2.4
7.结果如下