1、先安装一些依赖文件:
$ sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev libjpeg-dev, libpng-dev, libtiff4-dev, libjasper-dev, libdc1394-22-dev
2、下载源码安装
$ cd ~/your_working _directory
$ git clone https://github.com/opencv/opencv.git
3、编译
cd ~/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
5、修改相关文件
$ sudo vim /etc/ld.so.conf
文件末尾添加一行:/usr/local/lib
$ sudo ldconfig
$ sudo vim /etc/bash.bashrc
文件末尾添加:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
至此, opencv已成功安装,可在/home/zs/opencv/samples/cpp编译例子进行检验,例如:
$ cd /example_cmake
$ g++ `pkg-config --cflags opencv` -o example example.cpp `pkg-config --libs opencv`
会生成一个example的可执行文件
$ ./example