概要
CentOS 7 に OpenCV git 最新版 (3.0.0-rc1) をインストールする - Qiita
上記urlを参考にさせて頂きました。
ただし、
$ make -j : g++: internal compiler error: Killed (program cc1plus)
のようなメモリ不足?によるエラーとなった為、「make」としました。
また、
$ make : In file included from /home/endo/tmp/opencv/modules/videoio/src/cap_ffmpeg.cpp:47:0: /home/endo/tmp/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In function ‘AVStream* icv_add_video_stream_FFMPEG(AVFormatContext*, AVCodecID, int, int, int, double, int)’: /home/endo/tmp/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1573:21: error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope c->flags |= CODEC_FLAG_GLOBAL_HEADER; : /home/endo/tmp/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In static member function ‘static AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext*, AVCodecID, int, int, int, double, AVPixelFormat)’: /home/endo/tmp/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2379:25: error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope c->flags |= CODEC_FLAG_GLOBAL_HEADER; ^ make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o] Error 1 make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2 make: *** [all] Error 2
ようなエラーもありました。ググると、opencv3.3.1 が ffmpeg3.4に対応していないようでしたので ver.3.2.9を使用しています。
詳細
# yum install autoconf automake cmake freetype-devel gcc gcc-c++ \ git libtool make mercurial nasm pkgconfig zlib-devel
$ git clone git://github.com/yasm/yasm.git $ cd yasm $ autoreconf -fiv $ ./configure $ make # make install
$ wget http://www.nasm.us/pub/nasm/releasebuilds/2.13.01/nasm-2.13.01.tar.gz $ tar -xvf nasm-2.13.01.tar.gz $ cd nasm-2.13.01 $ ./configure $ make # make install
$ git clone git://git.videolan.org/x264 $ cd x264 $ ./configure --enable-static --enable-pic $ make # make install
$ git clone git://git.code.sf.net/p/opencore-amr/fdk-aac $ cd fdk-aac $ autoreconf -fiv $ ./configure --disable-shared --with-pic $ make # make install
$ wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz $ tar -xvf lame-3.99.5.tar.gz $ cd lame-3.99.5 X $ ./configure --disable-shared --enable-nasm --with-pic $ ./configure --enable-nasm --with-pic $ make # make install
$ git clone git://git.opus-codec.org/opus.git $ cd opus $ autoreconf -fiv X $ ./configure --disable-shared --with-pic $ ./configure --with-pic $ make # make install
$ wget http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz $ tar xzvf libogg-1.3.2.tar.gz $ cd libogg-1.3.2 $ ./configure --disable-shared --with-pic $ make # make install
$ wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz $ tar xzvf libvorbis-1.3.4.tar.gz $ cd libvorbis-1.3.4 X $ ./configure --with-ogg --disable-shared --with-pic $ ./configure --with-ogg --with-pic $ make # make install
$ git clone https://chromium.googlesource.com/webm/libvpx.git $ cd libvpx $ ./configure --disable-examples --enable-pic $ make # make install
# echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/usr-local-lib.conf # ldconfig
$ wget http://ffmpeg.org/releases/ffmpeg-3.2.9.tar.gz $ tar -xvf ffmpeg-3.2.9.tar.gz $ cd ffmpeg-3.2.9 $ PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure \ --enable-gpl --enable-nonfree --enable-libfdk_aac \ --enable-libfreetype --enable-libmp3lame --enable-libopus \ --enable-libvorbis --enable-libvpx --enable-libx264 \ --enable-pic --disable-static --enable-shared $ make # make install
$ git clone https://github.com/Itseez/opencv.git $ cd opencv $ mkdir build $ cd build $ PKG_CONFIG_PATH=/usr/local/lib/pkgconfig cmake \ -DPNG_INCLUDE_DIR=/usr/local/include \ -DPNG_LIBRARY_RELEASE=/usr/local/lib/libpng16.so \ .. $ make # make install
cmakeのオプションに -DPNG_INCLUDE_DIR と -DPNG_LIBRARY_RELEASE を付けています。 これは、私の環境にlibpng yum install版と、src install版があり、 次のようなエラーとなった為です
$ /usr/local/bin/opencv_createsamples \ -img window_900.png -vec window_900.vec \ -num 1000 -bgcolor 255 -w 50 -h 100 : Create training samples from single image applying distortions... libpng warning: Application built with libpng-1.6.32 but running with 1.5.13