8
5

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.

Raspberry PiAdvent Calendar 2018

Day 3

ラズパイ向けのOpenCVを、x86_64機のDockerでビルド

Last updated at Posted at 2018-12-02

ラズパイ向けのOpenCV 4を、x86_64機のDockerでビルド

概要

  • ラズパイ向けのOpenCVを、x86_64機のDockerでビルドします。
  • docker で、 qemuを使うので、結構時間がかかる。

環境

ビルド手順

  1. 準備

    # 1. スクリプトを取得
    git clone https://github.com/mt08xx/opencv-rpi-buildenv-docker
    
    # 2. gitのフォルダに移動
    cd opencv-rpi-buildenv-docker
    
    # 3. docker のインストール(必要あれば)
    sudo ./inst_docker.sh
    
    # 4. dockerグループに参加
    sudo usermod -aG docker $USER
    
    # 5. ARMのバイナリ実行のための、qemuとbinfmt関係をインストール
    sudo ./inst_prereq.sh
    
  2. 一度再起動

6. 再起動

sudo reboot


3. コンテナを作成

	```bash
	# 7. ビルド環境のコンテナを作成
	cd ~/opencv-rpi-buildenv-docker
	docker build . -t mt08/opencv-rpi-buildenv
	```

	```shell-session:このぐらい
	$ time docker build . -t mt08/opencv-rpi-buildenv
	real    16m50.195s
	user    0m0.597s
	sys     0m0.317s
	```

4. ソースの取得・解凍

	```bash:OpenCV4.0.0のソース取得・解凍
	cd ~/opencv-rpi-buildenv-docker
	./dl_opencv.sh 4.0.0
	```

5. ビルド

	```bash
	OPENCV_VERSION=4.0.0
	WORKDIR=build
	NUM_JOBS=8
	#
	cd ~/opencv-rpi-buildenv-docker
	# 
	mkdir -p opencv-${OPENCV_VERSION}/${WORKDIR}
	# 
	# cmake コンフィグレーション
	time docker run -it --rm -v `pwd`:/build -w /build/opencv-${OPENCV_VERSION}/${WORKDIR} --name opencv-rpi mt08/opencv-rpi-buildenv ../../conf_opencv.sh ${OPENCV_VERSION} 2>&1 | tee build_conf.log
	#
	# make
	time docker run -it --rm -v `pwd`:/build -w /build/opencv-${OPENCV_VERSION}/${WORKDIR} --name opencv-rpi mt08/opencv-rpi-buildenv make -j ${NUM_JOBS} 2>&1 | tee build_make.log
	```





    ```shell-session:24-logical-coreで、NUM_JOBS=60にて
real    81m54.272s
user    0m0.569s
sys     0m0.274s
  1. インストールファイル

    # インストール ./usr_local フォルダに必要なものが入る
    OPENCV_VERSION=4.0.0
    WORKDIR=build
    time docker run -it --rm -v `pwd`:/build -w /build/opencv-${OPENCV_VERSION}/${WORKDIR} -v `pwd`/usr_local:/usr/local --name opencv-rpi mt08/opencv-rpi-buildenv make install 2>&1 | tee build_install.log  
    #
    # アーカイブ作成
    cd usr_local
    tar jcvf ../opencv-${OPENCV_VERSION}-rpi.tbz .
    ls -l ../*.tbz 
    

    ```shell-session
## make install
real    3m50.976s
user    0m0.078s
sys     0m0.148s

ラズパイでの実行

  1. 必要なパッケージのインストール

    sudo apt-get update && \
    sudo apt-get install \
    	libjpeg62-turbo libtiff5 libjasper1 libpng16-16 \
    	libavcodec57 libavformat57 \
    	libatlas3-base liblapack3 \
    	libswscale4 libv4l-0 libxvidcore4 libx264-148 \
    	libgtk2.0-0 libgtk-3-0 libcanberra-gtk0 libcanberra-gtk3-0 \
    	libavresample3 libtesseract3 liblept5 libhdf5-100 \
    	libgstreamer1.0-0 libgstreamer-plugins-base1.0-0 
    
  2. ↑でできた、opencv-4.0.0-rpi.tbzをラズパイに持ってくる

  3. /usr/localに解凍

sudo tar jxvf ./opencv-4.0.0-rpi.tbz -C /usr/local
sudo ldconfig

その他

  1. (TODO) 普通のノートパソコンでのビルド時間 ?
  2. (TODO) debパッケージ作成 ?
8
5
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
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?