おのたく日記 YouTubeも始めました→
2007-06-24(Sun) USBカメラで監視 [長年日記]
■ USBカメラで監視
「なんか泥棒が増えているようだ」ということで、Webcamを使って監視を開始することにした。
まずはUSBカメラだけど、2001年頃にYAMADA電器で安かったので二台ほど買ったICM64481というカメラを利用。
参照:
Debian 4.0(etch)に接続すると
Jun 16 06:10:26 server kernel: drivers/media/video/ov511.c: USB OV511+ video device found
Jun 16 06:10:26 server kernel: drivers/media/video/ov511.c: model: Generic Camera (no ID)
Jun 16 06:10:26 server kernel: drivers/media/video/ov511.c: Sensor is an OV7620
Jun 16 06:10:27 server kernel: drivers/media/video/ov511.c: Device at usb-0000:00:1d.2-2 registered to minor 1
Jun 16 06:10:27 server kernel: usbcore: registered new interface driver ov511
Jun 16 06:10:27 server kernel: drivers/media/video/ov511.c: v1.64 for Linux 2.5 : ov511 USB Camera Driver
と難なく認識して、
$ xawtv -c /dev/video1 -geometry 640x480
で映像がとれることが確認できた。(video1なのはvideo0にはTVチューナになっているから)
つぎは、ビデオのようにずっと録画しっぱなしにするのも後で見直すのも面倒だし、DISKも圧迫してしまう。そこで、カメラを監視していて動きがあるときにだけ画像を記録できる「motion」debパッケージをインストールして、これで動作検知して監視することにする。
moitionをインストールすると、設定ファイルは/etc/motion/motion.confに最低限は書いてあるけど、もう少しくわしく設定したいので、/usr/share/doc/motion/examplesを参考に
framerate 4
#8だとぶれる
# Automatically tune the threshold down if possible (default: off)
threshold_tune on
# Enables motion to adjust its detection/noise level for very dark frames
# Don't use this with noise_tune on. (default: off)
night_compensate on
# Picture frames must contain motion at least the specified number of frames
# in a row before they are detected as true motion. At the default of 1, all
# motion is detected. Valid range: 1 to thousands, recommended 1-10
minimum_motion_frames 2
# Target base directory for pictures and films
# Recommended to use absolute patch. (Default: current working directory)
target_dir /var/spool/motion
# Minimum gap in seconds between the storing pictures while detecting motion.
# Default: 0 = as fast as possible (given by the camera framerate)
# Note: This option has nothing to do with the option 'gap'
minimum_gap 10
# Locate and draw a box around the moving object.
# Valid values: on, off and preview (default: off)
# Set to 'preview' will only draw a box in preview_shot pictures.
locate on
#on_motion_detected
on_picture_save /etc/motion/picmail.sh /var/spool/motion/%v-%Y%m%d%H%M%S-%q.jpg
というような設定をした。一番最後の行のpicmail.shは、画像を添付ファイルでGoogleのサービスgmailに転送するShellスクリプト。
泥棒におうちサーバを盗まれてしまって折角検知した画像が見えないということを避けるために、認識したらすぐに外に画像をおうちの外に保存しておくためにこのような設定にした。
#こういう時に、gmailの2.5GBという大容量はありがいですね〜
上の画像はマシン室の前を横切ったときですが、こんな感じでおうちのマシン室の入口を監視できるようになりました。
motionは、AXIS製のネットワークカメラ(もちろん無線LANも)に対応しているようなので、これを利用してマシン室以外の玄関なども監視していくようにしたいな。
|