1.更新系统
sudo apt-get update
sudo apt-get upgrade
2.安装相关的依赖
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libjasper-dev libatlas-base-dev gfortran
3.下载OpenCV
git clone https://github.com/opencv/opencv.git
4.进入到OpenCV所在的路径
cd opencv
mkdir build
5.编译安装
依次输入如下命令:
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j4
sudo make install
sudo nano /etc/dphys-swapfile
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
g++ -o test_opencv test_opencv.cpp `pkg-config opencv --cflags --libs`
./test_opencv