7
13

More than 5 years have passed since last update.

ラズパイ+Webカメラでタイムラプス撮影してみた 撮影設定編

Last updated at Posted at 2015-11-03

前回 環境構築編 の続きです。

Webカメラ占有問題

Webカメラで画像を撮影できるソフトをインストールし,試してみるWebカメラが占有されており,撮影に失敗しました。

$ fswebcam a.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Error selecting input 0
VIDIOC_S_INPUT: Device or resource busy // デバイスが占有されている

プロセスを観察し,動作しているアプリケーションを調べていくと

motionというWebカメラを使うツールが起動している事が判明

$ ps ax

2212 ? Sl 0:05 /usr/bin/motion
~~~
```

自動起動しているのでこのサービスを停止,自動起動しないようにします。

参考
Debianの不要なサービスの自動起動を停止

unlevel を調べる

# runlevel
N 2

runlevel 2で起動されるサービスを参照しmotionの自動起動設定を発見

サービスを停止し,自動起動の設定を消去する

そして,再起動し,motionが自動起動していないことを確認

$ ls -la /etc/rc2.d/ |grep motion
lrwxrwxrwx   1 root root   16  6月 26 22:54 S02motion -> ../init.d/motion
# /etc/rc2.d/S02motion stop // サービスの停止
[ ok ] Stopping motion detection daemon: motion.
# update-rc.d motion remove //自動起動設定の消去
update-rc.d: using dependency based boot sequencing

# reboot

# ps ax |grep motion
 2366 pts/0    S+     0:00 grep --color=auto motion

$ fswebcam -r 640x512 -d /dev/video0 test.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 640x512 to 640x480.
--- Capturing frame...
Captured frame in 0.00 seconds.
--- Processing captured image...
Writing JPEG image to 'test.jpg'. // 撮影出来た

一定間隔で撮影するスクリプトを作成

Web Camera BSW32KM03BKでうまくいった設定は以下のとおり

Capture.sh
# bin/Bash

while true; do
    sleep 10;
    fswebcam --no-banner -p MJPEG -S 2 --set brightness=55% --set "White Balance Temperature, Auto"=False -r 1920×1080 /home/pi/timelapse/`date +%Y%m%d/%H-%M-%S`.jpg;
done

setのオプションで設定できる項目はカメラによって異なるようです

確認は--list-controlsオプションで確認できます

$ fswebcam -d /dev/video0 --list-controls
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Available Controls        Current Value   Range
------------------        -------------   -----
Brightness                25 (54%)        -255 - 255
Contrast                  32 (12%)        0 - 255
Saturation                64 (25%)        0 - 255
Hue                       0               -4 - 4
White Balance Temperature, Auto False           True | False
Gamma                     100 (17%)       16 - 500
Power Line Frequency      60 Hz           Disabled | 50 Hz | 60 Hz
White Balance Temperature 5200 (66%)      2662 - 6500
Sharpness                 25 (19%)        0 - 127
Backlight Compensation    0               0 - 1
Adjusting resolution from 384x288 to 352x288.
--- Capturing frame...
Captured frame in 0.00 seconds.
--- Processing captured image...
There are unsaved changes to the image.

カメラをアクティブにした数フレームは映像が正しく撮影できない問題が発生していました

そこで,以下のオプションでカメラをアクティブにして2フレーム後に撮影するようにしました

-S 2

デフォルトで色温度の自動調整がTrueになっていました

これが有効になっていると,コマンドを実行した瞬間に色温度の調整と撮影を始めるようで,暗さがバラバならタイムラプスになってしまいました.

そこで以下のオプションを利用

--set "White Balance Temperature, Auto"=False

自動起動設定

作成したCapture.shに実行権限を与え,RaspberryPiが起動した際に撮影を開始するように設定します

RaspberryPiの環境では起動時に /etc/rc.local に記述されたスクリプトを実行するようです

なので,rc.localのexitの文より先に撮影用のCapture.shをバックグラウンドで実行するようにしました

rc.local
# vim /etc/rc.local

Add for Capture Timelaspse!

sh /home/pi/timelapse/capture.sh&

exit 0
```

これで準備は完了撮影ができます!

続く

次回は,後処理編 として,撮影した写真たちを動画にする処理について書きたいと思います.

7
13
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
7
13