##1、更新源
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
##2、安装依赖库
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
sudo apt install libjasper1 libjasper-dev
sudo apt-get install ffmpeg
##3.FFMPEG 编译报错
在 opencv-3.1.0/modules/videoio/src/cap_ffmpeg_impl.hpp 里最顶端添加:
#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
#define AVFMT_RAWPICTURE 0x0020
##4. const char* 转char报错
在 opencv-3.1.0/modules/python/src2/cv2.cpp 730行改为
char str = (char*)PyString_AsString(obj);
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make -j4
sudo make install