Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@motoJinC25

Raspbian Busterにて最新のOpenCVインストール

More than 1 year has passed since last update.

概要

最新のOpenCV(v4.1.2)をRaspbian Busterでソースコンパイルしてインストールした内容のメモです。

環境確認

LinuxバージョンとPythonバージョン確認

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:    10
Codename:   buster

$ python3 --version
Python 3.7.3

必要パッケージインストール

# パッケージアップデート
$ sudo apt-get update && sudo apt-get upgrade

# ビルドツールインストール
$ sudo apt install -y build-essential cmake pkg-config

# イメージ関連パッケージインストール
$ sudo apt install -y libjpeg-dev libtiff5-dev libjasper-dev libpng-dev

# ビデオ関連パッケージインストール
$ sudo apt install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev

# OpenCV関連パッケージインストール
$ sudo apt install -y libfontconfig1-dev libcairo2-dev libgdk-pixbuf2.0-dev libpango1.0-dev libgtk2.0-dev libgtk-3-dev libatlas-base-dev gfortran

# Python関連パッケージインストール
$ sudo apt install -y python3-dev

Swapサイズ変更

$ sudo vi /etc/dphys-swapfile
...
CONF_SWAPSIZE=100 --> 2048
...

$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start

OpenCVインストール

約2~3時間かかるので、tmuxを使いましょう。

ソースダウンロード

$ cd ~
$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.1.2.zip
$ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.1.2.zip
$ unzip opencv.zip
$ unzip opencv_contrib.zip
$ mv opencv-4.1.2 opencv
$ mv opencv_contrib-4.1.2 opencv_contrib

ソースコンパイル

$ cd ~/opencv
$ mkdir -p build && cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D CMAKE_SHARED_LINKER_FLAGS=-latomic \
-D BUILD_EXAMPLES=OFF ..

# 2~3時間所要
$ make -j4

$ sudo make install
$ sudo ldconfig

OpenCV確認

Swapサイズ変更

$ sudo vi /etc/dphys-swapfile
...
CONF_SWAPSIZE=2048 --> 100
...

$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start

OpenCVリンク修正

$ cd /usr/local/lib/python3.7/dist-packages/cv2/python-3.7
$ sudo mv cv2.cpython-37m-arm-linux-gnueabihf.so cv2.so
$ cd ~/.local/lib/python3.7/site-packages/
$ ln -s /usr/local/lib/python3.7/dist-packages/cv2/python-3.7/cv2.so cv2.so

バージョン確認

$ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.1.2'
>>>
0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
motoJinC25
株式会社 motojin.com の創業者。ソリューションアーキテクト兼代表取締役社長。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?