2
3

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.

opencv3.4.0インストールメモ

Posted at

ソースをダウンロードして展開

.sh
$ cd ~
$ mkdir temp
$ cd temp
$ wget https://github.com/opencv/opencv/archive/3.4.0.zip -O opencv-3.4.0.zip
$ wget https://github.com/opencv/opencv_contrib/archive/3.4.0.zip -O opencv_contrib-3.4.0.zip
$ unzip opencv-3.4.0.zip
$ unzip opencv_contrib-3.4.0.zip
$ cd opencv-3.4.0
$ mkdir build
$ cd build

$HOME/temp/opencv/opencv-3.4.2/modules/python/src2/cv2.cpp の885行目を以下のように修正

.cpp
const char* str = PyString_AsString(obj);

コンパイル&インストール

cuda9.1がインストールされている。
システムにはpython3.7がインストールされている。
それとは別に python3.7.0 を pyenv で global に指定していて普段はそれを使っている。

.sh
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D ENABLE_CXX11=1 \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D HAVE_opencv_python3=ON \
-D PYTHON_DEFAULT_EXECUTABLE=$HOME/.pyenv/versions/3.7.0/bin/python3.7 \
-D PYTHON_EXECUTABLE=$HOME/.pyenv/versions/3.7.0/bin/python3.7 \
-D PYTHON_INCLUDE_DIRS=$HOME/.pyenv/versions/3.7.0/include/python3.7m \
-D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.7m.so.1 \
-D INSTALL_C_EXAMPLES=OFF -D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.0/modules \
-D BUILD_EXAMPLES=ON ..
.sh
$ make -j8
$ sudo make install
$ sudo ldconfig
$ cd ~/.pyenv/versions/3.7.0/lib/python3.7/site-packages
$ sudo ln -s /usr/local/lib/python3.7/site-packages/cv2.cpython-37m-x86_64-linux-gnu.so cv2.so

チェック

.sh
$ cd ~
$ python
Python 3.7.0 (default, Jul 26 2018, 05:22:48) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.0'
>>> exit()
2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?