0
0

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 3 years have passed since last update.

Ubuntu Mate 18.04 on Raspberry Pi 4 Model BでD435iの動作確認をする

Last updated at Posted at 2021-03-05

前準備

Swap領域の拡張

搭載メモリ2GB版Raspberry Pi 4ではビルド中にフリーズするので、Swap領域を拡張しておく。

sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo sh -c 'echo "/swapfile\tnone\tswap\tsw\t0\t0" >> /etc/fstab'

pythonコマンドのデフォルトをPython3に変更

Python2系は使わない方針なので、システムのPythonのデフォルトをPython3系になるように設定する。

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.6   2         auto mode
  1            /usr/bin/python2.7   1         manual mode
  2            /usr/bin/python3.6   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

D435iの動作確認

aptでお手軽にlibrealsense2をインストールする方法だと、距離画像と姿勢は取得できたものの、RGBカラー画像が取得できなかった。
https://github.com/IntelRealSense/librealsense/blob/master/doc/distribution_linux.md

librealsenseのビルドとインストール

ビルドに必要とされるもの一式を、インストールしておく。

sudo apt install git libssl-dev libusb-1.0-0-dev pkg-config libgtk-3-dev
sudo apt install libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev

IntelのGitHubレポジトリからlibrealsenseをクローンしてきて、ビルドする。

cd ~
git clone https://github.com/IntelRealSense/librealsense
git checkout -b v2.34.0 refs/tags/v2.34.0
cd librealsense
mkdir build
cd build
cmake ../ -DCMAKE_BUILD_TYPE=release -DBUILD_EXAMPLES=true -DBUILD_GRAPHICAL_EXAMPLES=true
sudo make uninstall && make clean && make -j 4 && sudo make install

執筆時点ではv2.34.0以降だと、このあとにpyrealsense2を使おうとすると、インストールはされるのにうまく動かなかったので、v2.34.0でチェックアウトした。
https://github.com/IntelRealSense/librealsense/issues/6820

また、SDカードのSwap領域にSwapoutするためか、ビルドにはかなり時間がかかった(約3時間)。

udevの設定をコピーして、反映させる。

sudo cp ../config/99-realsense-libusb.rules /etc/udev/rules.d/99-realsense-libusb.rules && sudo udevadm control --reload-rules && udevadm trigger

RealSense Viewerを起動する。

realsense-viewer

"Stereo Module"、"RGB Camera"、"Motion Module"のそれぞれの右側にある"off"を、ポインティングデバイスでクリックして、"on"にする。

以下のような表示になれば、動作確認完了。

realsense-viewew.png

当初、v2.36.0のrealsense-viewerで確認をしていて、起動直後にファームウェアの更新がかかっていたせいかもしれないが、v2.34.0のrealsense-viewerで起動直後に"Invalid Value in rs2_get_option"Warningのダイアログが出たり、常に"Failed to read busnum/devnum."が出力されたりする。

pyrealsense2のビルドとインストール

sudo apt install python-dev

cmake ../ -DCMAKE_BUILD_TYPE=release -DBUILD_EXAMPLES=true -DBUILD_GRAPHICAL_EXAMPLES=true -DBUILD_PYTHON_BINDINGS=true -DPYTHON_EXECUTABLE=$(which python3)

make -j 4 && sudo make install

echo 'export PYTHONPATH=$PYTHONPATH:/usr/local/lib' >> ~/.bashrc

source ~/.bashrc

ここでも、SDカードのSwap領域にSwapoutするためか、ビルドにはかなり時間がかかった(約1-2時間)。

Pythonのサンプルコードを実行して、動作確認をする。

pip opencv-python
cd ../wrappers/python/examples
python align-depth2color.py

以下のような表示になれば、動作確認完了。

pyrealsemse2_example.png

距離閾値よりも遠くにあるピクセルがグレーで塗りつぶされて、手前の物体の描画が残るようになっている。

参考サイト

https://demura.net/education/17957.html
https://codechacha.com/ja/change-python-version/
https://qiita.com/nv-h/items/3bd206bebf9303dd6624

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?