LoginSignup
13
15

More than 5 years have passed since last update.

CentOS7にOpenCVをインストールする

Last updated at Posted at 2017-09-03

最小限にインストールしてみます。

必要なものをインストールする

rootで作業します。
まずはOpenCVのサイトを参考に必要そうなものをインストールします。

$ su -
# yum install -y git gcc bzip2 bzip2-devel openssl openssl-devel readline readline-devel sqlite-devel
# yum install -y cmake libjpeg-devel libtiff-devel libpng-devel jasper-devel
# yum install -y mesa-libGL-devel libXt-devel libgphoto2-devel nasm libtheora-devel
# yum install -y autoconf automake gcc-c++ libtool yasm openal-devel blas blas-devel atlas atlas-devel lapack lapack-devel
# yum install -y numpy

OpenCVをビルドしてインストールする

githubのソースコードからビルド・インストールします。
このあたりも公式サイト通りです。

# cd /usr/local/src
# git clone https://github.com/opencv/opencv.git
# cd opencv
# mkdir build
# cd build
# cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
# make -j7
# make install

共有ライブラリ情報を追加します。

# echo /usr/local/lib > /etc/ld.so.conf.d/opencv.conf
# ldconfig -v

確認する

ちゃんとインストールできたか確認します。

まずは適当なフリー画像をwgetしておきます。

$ wget http://hogehoge/hogehoge.jpg ./data/w001.jpg
$ ls data/
w001.jpg

確認はC++ですることにします。
先ほどダウンロードした画像を読み込み、確認として「画像の高さ」を出力するプログラムです。

opencvtest.cpp
#include <iostream>
#include <opencv2/opencv.hpp>

int main(int argc, const char* argv[]) {
   std::cout << "start -- \n";

   cv::Mat image = cv::imread("data/w001.jpg" , 0);
   if (image.empty()) {
      std::cout << "read error.\n";
      return -1;
   }

   std::cout << image.rows ;

   std::cout << "\nend -- \n";
   return 0;
}

コンパイルして実行します。

$ g++ -o opencvtest opencvtest.cpp -I/usr/local/include/opencv2 -I/usr/local/include/opencv -L/usr/local/lib -lop
encv_core -lopencv_imgcodecs -lopencv_highgui
$ ./opencvtest
start --
1200
end --

高さ「1200」なので合っていますね。

インストールだけで疲れたので、続きはまた今度です。

参考

http://docs.opencv.org/3.3.0/d7/d9f/tutorial_linux_install.html
http://qiita.com/twaka/items/7555785aea11879d6718
http://nephy.hateblo.jp/entry/2016/09/18/153804

13
15
4

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
13
15