LoginSignup
8
11

More than 5 years have passed since last update.

Raspberry PiとWebカメラで静止画像を1分ごとに撮影し続ける手順メモ

Posted at

概要

Raspberry PiとWebカメラで静止画像を1分ごとに撮影し、画像を保存し続ける手順メモ。
8時~22時の間、1分おきに YYYYmmdd-HHMMSS.jpg という画像ファイルが出力される

前提(機材等)

  • OS(Rasbian)がインストールされていること
  • Raspberry Piにログイン(ターミナル操作)できること

Wi-Fi内蔵してたようだが、よくわからなかったので、実績のあったアダプタを使用した。
その他、ケーブルやディスプレイ等は適宜。

構築手順

OS環境設定

以下を参考にタイムゾーンやキーボードの設定を行う
Raspberry Piの設定【raspi-config/言語・タイムゾーン・キーボードの設定】 - Aldebaranな人のブログ

Wi-Fi設定

# wpa_passphrase [SSID] [Password]
※出力されたハッシュ値を控えておく
# cat /etc/wpa_supplicant/wpa_supplicant.conf
country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
        ssid="[SSID]"
        psk=[出力されたハッシュ値]
        key_mgmt=WPA-PSK
        proto=WPA2
        pairwise=TKIP CCMP
        group=TKIP CCMP
        priority=2
}

# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp

# reboot

参考:tkamada_の日々: Raspberry PiのWiFi設定-DHCPから固定IPアドレスまで最速版

パッケージ類インストール等

# apt-get update
# apt-get upgrade
# apt-get install vim
# apt-get install chkconfig
# apt-get install fswebcam

シェルスクリプト配置

シェルスクリプト

/root/image/scan.sh
#!/bin/sh
fswebcam /root/image/`date "+%Y%m%d-%H%M%S"`.jpg

実行権限付与

# chmod u+x /root/image/scan.sh

※ fswebcamでエラーが出る場合、カメラを接続して再起動したら動いた

Cron配置

8時~22時の間、1分おきに実行する。

# crontab -l
*/1 8-22 * * * /root/image/scan.sh
8
11
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
8
11