教程1: Opencv3.0.0-alpha在ubuntu16.04的安装

# step 1 
# 安装依赖 (太多了,自己相应替换)
sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip 

sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip --fix-missing


# step 2
# 下载解包
wget https://github.com/Itseez/opencv/archive/3.0.0-alpha.zip
unzip opencv-3.0.0-alpha.zip
# step 3
# 编译
cd opencv-3.0.0-alpha
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
# step 4
#安装
make 
sudo make install

# step 5
# 安装完成,进行整理 
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
sudo apt-get update

教程2:
今天重装了Opencv3.20 和Opencv3.2.0conbtrib,将安装日志记录如下:
1. 查询自己的Opencv版本 pkg-config --modversion opencv
2. 下载Opencv3.2.0 和Opencv contrib3.2.0 对于opencv3.2.0 https://pan.baidu.com/s/1bp03gab 对于Opencv3.2.0 contrib
3. 卸载当前的Opencv ,进入安装的build目录,执行 sudo make uninstall ,然后cd .. 执行rm -rf build
4. 清理/usr中所有的opencv相关选项 rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
5. 执行 sudo make -j16sudo make install , 在make的时候我遇到一个问题就是fatal error: LAPACKE_H_PATH-NOTFOUND/lapacke.h: No such file or directory #include “LAPACKE_H_PATH-NOTFOUND/lapacke.h” 原因:未找到lapacke.h文件 ,只需要sudo apt-get install liblapacke-dev checkinstall就可以解决继续make了。成功后进行第5步。
6. cd /usr
7. find . -name "*opencv*" | xargs sudo rm -rf
8. 成功后在终端中打开 /etc/ld.conf.d/opencv.conf 文件,并在最后一行添加 /usr/local/lib,如果没有这个文件那就新建一个。然后打开 /etc/bash.bashrc 文件,在最后一行中添加

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv320/lib/pkgconfig
export PKG_CONFIG_PATH

最后. sudo ldconfig生效

备注:最后使用pkg-config --modversion opencv查询版本如果报错为:

Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

则需要运行下边语句:

sudo cp /usr/local/opencv320/lib/pkgconfig/opencv.pc /usr/lib/pkgconfig