LoginSignup
25
25

More than 5 years have passed since last update.

CentOS 7 に OpenCV git 最新版 (3.0.0-rc1) をインストールする

Last updated at Posted at 2015-06-25

概要

CentOS 7 に OpenCV の git 最新版をソースからビルドしてインストールする手順を紹介します.
依存関係にある FFmpeg と cuda のインストール手順もあわせて記載します.

環境

$ uname -a
Linux mhws5 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/centos-release
CentOS Linux release 7.1.1503 (Core)

手順

1. ビルドに必要な環境の準備

$ sudo yum install autoconf automake cmake freetype-devel gcc gcc-c++ git libtool make mercurial nasm pkgconfig zlib-devel

2. FFmpeg の依存関係のインストール

  • 注1: 以下は Compile FFmpeg on CentOS に記載の手順とほぼ同じですが,opencv のビルド時に FFmpeg を静的リンクするため, -fPIC オプションを有効にしています.
  • 注2: 上記リンクにおける ffmpeg_source ディレクトリは使いません./usr/local以下にインストールされます.
  • 注3: libx265 はインストールしません(何故か ffmpeg のビルドが通らなかったため).

Install Yasm

$ git clone git://github.com/yasm/yasm.git
$ cd yasm
$ autoreconf -fiv
$ ./configure
$ make -j
$ sudo make install

Install libx264

$ git clone git://git.videolan.org/x264
$ cd x264
$ ./configure --enable-static --enable-pic
$ make -j
$ sudo make install

Install libfdk_aac

$ git clone git://git.code.sf.net/p/opencore-amr/fdk-aac
$ cd fdk-aac
$ autoreconf -fiv
$ ./configure --disable-shared --with-pic
$ make -j
$ sudo make install

Install libmp3lame

$ curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
$ tar xzvf lame-3.99.5.tar.gz
$ cd lame-3.99.5
$ ./configure --disable-shared --enable-nasm --with-pic
$ make -j
$ sudo make install

Install libopus

$ git clone git://git.opus-codec.org/opus.git
$ cd opus
$ autoreconf -fiv
$ ./configure --disable-shared --with-pic
$ make -j
$ sudo make install

Install libogg

$ curl -O 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 -j
$ sudo make install

Install libvorbis

$ curl -O 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
$ ./configure --with-ogg --disable-shared --with-pic
$ make -j
$ sudo make install

Install libvpx

$ git clone https://chromium.googlesource.com/webm/libvpx.git
$ cd libvpx
$ ./configure --disable-examples --enable-pic
$ make -j
$ sudo make install

3. FFmpeg のインストール

PKG_CONFIG_PATH の設定は必須です.

$ git clone git://source.ffmpeg.org/ffmpeg
$ cd ffmpeg
$ 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 -j
$ sudo make install

ldconfig しておく

$ echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/usr-local-lib.conf
$ sudo ldconfig

正しくインストールできていることの確認

$ ffmpeg -version
ffmpeg version N-73155-gd5a36ed Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8.3 (GCC) 20140911 (Red Hat 4.8.3-9)
configuration: --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
libavutil      54. 27.100 / 54. 27.100
libavcodec     56. 45.100 / 56. 45.100
libavformat    56. 38.102 / 56. 38.102
libavdevice    56.  4.100 / 56.  4.100
libavfilter     5. 18.100 /  5. 18.100
libswscale      3.  1.101 /  3.  1.101
libswresample   1.  2.100 /  1.  2.100
libpostproc    53.  3.100 / 53.  3.100

4. cuda のインストール

cuda のインストールには libvdpau と dkms が必要なため,事前に epel のレポジトリを追加しておく.

$ sudo rpm -ivh http://ftp-srv2.kddilabs.jp/Linux/packages/fedora/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
$ wget http://developer.download.nvidia.com/compute/cuda/7_0/Prod/local_installers/rpmdeb/cuda-repo-rhel7-7-0-local-7.0-28.x86_64.rpm
$ sudo rpm -ivh cuda-repo-rhel7-7-0-local-7.0-28.x86_64.rpm
$ sudo yum install cuda

5. opencv のインストール

ここにも PKG_CONFIG_PATH の設定が必要.

$ git clone https://github.com/Itseez/opencv.git
$ cd opencv
$ mkdir build
$ cd build
$ PKG_CONFIG_PATH=/usr/local/lib/pkgconfig cmake ..
$ make -j
$ sudo make install

これで opencv のインストールは完了です.サンプルの動作確認をしてみます.

$ cd ../samples
$ mkdir build
$ cd build
$ cmake ..
$ make -j
$ ./cpp/cpp-example-example
Built with OpenCV 3.0.0-dev
No capture

スクリーンショット 2015-06-26 0.47.00.png

25
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
25