3
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 1 year has passed since last update.

ラズパイで物体検出 bookworm対応版

Last updated at Posted at 2023-12-22

はじめに

2024年1月時点での最新版ラズベリーパイOS bookwormだと従来の方法では無理だったので覚書

実行環境

Distributor ID: DebianDescription: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
#bookwormでも確認済み
Python 3.9.2
USBカメラ

下準備

$ sudo apt upgrade
$ sudo apt install git
$ sudo apt install libatlas-base-dev
$ sudo raspi-config
 1.VNCの有効化
 2.レガシーカメラの有効化(あれば)

OSのアップデートとgit,開発ツールのインストール。
raspi-configでVNCとカメラを有効化にしておく。

ラズパイでカメラを使えるようにする

$ sudo view /boot/config.txt
# Automatically load overlays for detected cameras
camera_auto_detect=1

camera_auto_detect=1がコメントアウトしてたら#を外して有効化

libcamera-hello -t 0

これでカメラが動くか確認。

libcamera-helloコマンドで動かない場合、VNCから確認できる
メディア→キャプチャデバイス→
Videoデバイス名 /dev/video0
Audioデバイス名 hw:2,0

image.png

Tensorflow liteのインストール

$ cd /home/Username/Desktop
$ git clone https://github.com/tensorflow/examples --depth 1 tensorflow_examples
$ python3 -m pip install virtualenv
$ python --version
$ python3.9 -m venv tf #直前のコマンドで確認したPythonのバージョンで仮想環境を作る
$ source tf/bin/activate ★

★sourceを実行するとプロンプトの前に(tf)が表示される。
以降は仮想環境下でコマンドを実行する

(tf)$ python -m pip install --upgrade tflite
(tf)$ cd tensorflow_examples/lite/examples/object_detection/raspberry_pi
(tf)$ sh setup.sh
(tf)$ python -m pip install --upgrade tflite-support==0.4.3
(tf)$ python detect.py --model efficientdet_lite0.tflite

カメラが起動して、物体検出できれば成功

終わりに

最新版ラズパイOSだとpip関連でエラーが出まくるので仮想環境を使うのと、tflite-supportをアップグレードするのがミソ
ちなみにUSB接続ではなく、カメラモジュールだと色々試したがうまくいかず…今後の検証が待たれる。

3
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
3
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?