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.

ラズパイカメラで動体検知する 準備編

Last updated at Posted at 2020-12-27

モチベーション

ラズパイで画像認識させていろいろしたい。用途はまだはっきりとはしてないのですが、そのための準備として動体検知を動かしておく。

環境

  • RaspberryPi3B+
  • Raspbian 9.8
  • HiLetgo OV5647 5MP Raspberry Pi 3 カメラ OV5647 HDカメラモジュール
  • motion

準備

motionのinstall

sudo apt-get update
sudo apt-get install motion

ffmpeg libavcodec57 libavdevice57 libavfilter6 libavformat57 libavresample3
libavutil55 libmariadbclient18 libpostproc54 libpq5 libsdl2-2.0-0
libswresample2 libswscale4 mysql-common というライブラリに依存していることがわかります。

カメラモジュールをカーネルに組み込む

sudo modprobe bcm2835-v4l2

modprobeコマンドはカーネルモジュールの組み込み(ロード)と取り外し(アンロード)を行うコマンドです。
V4L2はVideo4Linux2の略で、
これを実行するとカメラがビデオデバイス(/dev/video0)として認識されます。

OS起動のたびに組み込むために/etc/modulesに一行追加します。

bcm2835-v4l2

設定

/etc/motion/motion.conf
設定は多岐に渡るが、ひとまず動いていることを確認したいので、
ブラウザから画像が見えるようにstream_localhost をoffにする。

# Restrict stream connections to localhost only (default: on)
stream_localhost off

動かしてみる

pi@raspberrypi:/var/log/motion $ sudo motion -n
[0:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf
[0:motion] [NTC] [ALL] motion_startup: Motion 4.0 Started
[0:motion] [NTC] [ALL] motion_startup: Logging to file (/var/log/motion/motion.log)

ちなみにmotionコマンドのオプションは以下の通り。-nはbackgroundではなく、foreground動かすという意味です。そのため停めるときはCtrl-Cで止めます。

-b                      Run in background (daemon) mode.
-n                      Run in non-daemon mode.
-s                      Run in setup mode.
-c config               Full path and filename of config file.
-d level                Log level (1-9) (EMG, ALR, CRT, ERR, WRN, NTC, INF, DBG, ALL). default: 6 / NTC.
-k type                 Type of log (COR, STR, ENC, NET, DBL, EVT, TRK, VID, ALL). default: ALL.
-p process_id_file      Full path and filename of process id file (pid file).
-l log file             Full path and filename of log file.
-m                      Disable motion detection at startup.
-h                      Show this screen.

chroniumからhttp://192.168.0.13:8081/ (192.168.0.13はラズパイのIPアドレス)にアクセス。

リアルタイムでブラウザからカメラ画像を見ることは確認できました。
まだ、動体検知しているかまではわかりませんね。
/var/lib/motion にいくと、動画(aviファイル)、静止画(jpeg)が残っていたので、意図せずカメラの前での動きを検知したようです。

image.png

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?