29
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ubuntu14.04にpython用にOpenCV3.0.0をインストール

Last updated at Posted at 2015-09-12

DeepLearning用に画像を加工するのにPythonでOpenCVが使いたかったので、インストールしました。以前まで2.4系を使っていたのですが、3.0.0も出てしばらく経つので、そろそろ最新版をインストールしようと試みました。

OpenCV3.0.0のソースの取得

$ cd ~/work/download
$ wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/3.0.0/opencv-3.0.0.zip
$ unzip opencv-3.0.0.zip

requirementのインストール

必要そうなのをかたっぱしインストール

$ sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen3-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev default-jdk ant libvtk5-qt4-dev

configure

ubuntuでは、WITH_FFMPEG=OFFを忘れずに。

$ 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_FFMPEG=OFF -D BUILD_opencv_python2=ON ..

make用にコア数を調べておく

$ grep -c ^processor /proc/cpuinfo
8

make&install

$ make -j8
$ sudo make install

インストール確認

cd ../sample/cpp
./cpp-example-facedetect lena.jpg
  • 怒られた
cannot connect to X server
  • 環境変数DISPLAYが原因っぽい
$ export -p | grep DISPLAY
"なにもでない"
  • 以下を設定
export DISPLAY=":0"
  • 再び実行すると、うまくいった

python用設定

  • こちらの通りに、しようとしたが
    /usr/local/lib/python2.7/dist-packages/
    にcv2.soがなぜかなかった。なので
$ find / -name cv2.so

で検索したら、ビルドフォルダにはあったので
そちらを/usr/local/lib/python2.7/site-packages/にコピー

$ cp ~/work/downloads/opencv-3.0.0/build/lib/cv2.so /usr/local/lib/python2.7/site-packages/

python確認

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.0.0'
>>> exit()

うまくいったみたい

参考

AMIにOpenCV3.0をインストールしてみる

Why cv2.so missing after opencv installed?

Thread: cannot connect to X server

29
26
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
29
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?