ubuntu 18.04安装opencv 3.1.0

1.参照Setup OpenCV on Linux

wget https://github.com/Itseez/opencv/archive/3.1.0.zip
unzip 3.1.0.zip
cd opencv-3.1.0
mkdir release
cd release
cmake -D WITH_CUDA=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv-3.1.0 ..
make all
sudo make install

其中,以上8步中,第6步和第7步分别遇到了问题,这两步的问题类型不一样,现分别将解决方法记录如下。

问题1: 运行第六步时[cmake -D WITH…]

卡在ICV: Downloading ippicv_linux_20151201.tgz...
参照 ubuntu下安装opencv3.2出现-- ICV: Downloading ippicv_linux_20151201.tgz…

  1. 下载ippicv_linux_20151201.tgz

  2. 下载完后替换opencv-3.1.0/3rdparty/ippicv/downloads/linux-*目录下的同名文件,重新cmake。

如果发现替换不成功,等报出错误后再更换,多试几次。

问题2:运行第七步时[make all]

出现以下错误:

在这里插入图片描述

提取出来如下:

In file included from /usr/include/c++/4.8/cstdint:35:0,
                 from /usr/include/OpenEXR/ImfFrameBuffer.h:55,
                 from /usr/include/OpenEXR/ImfInputFile.h:47,
                 from /home/xxx/Downloads/opencv-3.1.0/modules/imgcodecs/src/grfmt_exr.hpp:53,
                 from /home/xxx/Downloads/opencv-3.1.0/modules/imgcodecs/src/grfmts.hpp:53,
                 from /home/xxx/Downloads/opencv-3.1.0/modules/imgcodecs/src/loadsave.cpp:47:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^
modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/build.make:62: recipe for target 'modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/src/loadsave.cpp.o' failed

也即:
error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
参照#error This file requires compiler and library support for the ISO C++ 2011 standard…的方法,完美解决。

cd ~/Downloads/opencv-3.1.0/modules/imgcodecs
gedit CMakeLists.txt

在第一行下面添加:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

然后,保存,关闭文件。

重新make all