straightweeds.hatenablog.com

30代のシステムエンジニアが興味のあることだけ書くブログ

RaspberryPiを監視カメラに(motion)

RaspberryPiを監視カメラにできます。

Webカメラを買うだけで自宅のペットの確認などができるようになります。

f:id:straightweeds:20170416161620p:plain

カメラの準備

RaspberryPiに接続するカメラを購入します。 私はLogicoolのC270を使っています。

LOGICOOL ウェブカム HD画質 120万画素 C270

LOGICOOL ウェブカム HD画質 120万画素 C270

前提

動きがあった時の動画を保存しておきますが、保存先はCIFS共有にしています。 (RaspberryPi SDカードへの書き込みを抑制するため)

動きがあった時の動画以外に、一番動きのあったシーンを静止画でも保存する設定にしています。

お決まり

作業はrootで実施するのでsuしておきます。

$ su -

Installation

Install

  1. apt-getでインストール
# apt-get install motion

Initial Setting

  1. マウント先情報を編集
# nano /etc/fstab
//CIFSIP/raspberrypi_cifs/motion   /var/opt/motion     cifs username=CIFSユーザ名,password=CIFSパスワード,iocharset=utf8,rw,uid=1000,gid=1000,file_mode=0777,dir_mode=0777,defaults   0    0
  1. マウント先作成
# mkdir /var/opt/motion
  1. マウント
# mount /var/opt/motion
  1. 定義ファイル編集
# nano /etc/motion/motion.conf
norm 1
width 640
height 480
framerate 12
threshold 2000
output_pictures best
target_dir /var/opt/motion
stream_localhost off
webcontrol_localhost off
  1. PID格納先の作成
# mkdir /var/run/motion
  1. デーモン設定の変更
# nano /etc/default/motion
start_motion_daemon=yes
  1. サービス再起動
# service motion restart

これでhttp://RaspberryPiのIPアドレス:8081にアクセスすると画像が表示できます。

↓気が向いた時でいいのでポチって頂けると幸いです↓