Linux Install Memo

サーバー管理者によるLinux関連ソフトのインストールメモ

Home » □RaspberryPiというかRaspbianで動くWebCAM監視カメラ(ライブカメラ)

□RaspberryPiというかRaspbianで動くWebCAM監視カメラ(ライブカメラ)

WebCAM好きなので、RaspberryPiというかRaspbianで動くWebCAM監視カメラ
というかライブカメラをいくつか試してみました。

基本的にRaspbianにUVC対応のWebCAMをUSBにぷすっと刺せば、たいていは
一発認識してくれるでしょう、こんな感じで。

> Mar 13 00:26:13 raspberrypi kernel: [11539.274116] usb 1-1.2: new high-speed USB device number 4 using dwc_otg
> Mar 13 00:26:13 raspberrypi kernel: [11539.464441] usb 1-1.2: New USB device found, idVendor=056e, idProduct=7002
> Mar 13 00:26:13 raspberrypi kernel: [11539.464473] usb 1-1.2: New USB device strings: Mfr=2, Product=1, SerialNumber=0
> Mar 13 00:26:13 raspberrypi kernel: [11539.464490] usb 1-1.2: Product: USB2.0 PC Camera
> Mar 13 00:26:13 raspberrypi kernel: [11539.464505] usb 1-1.2: Manufacturer: Sonix Technology Co., Ltd.
> Mar 13 00:26:13 raspberrypi kernel: [11539.533959] Linux media interface: v0.10
> Mar 13 00:26:13 raspberrypi kernel: [11539.554342] Linux video capture interface: v2.00
> Mar 13 00:26:13 raspberrypi kernel: [11539.578225] uvcvideo: Found UVC 1.00 device USB2.0 PC Camera (056e:7002)
> Mar 13 00:26:13 raspberrypi kernel: [11539.586965] input: USB2.0 PC Camera as /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2:1.0/input/input0
> Mar 13 00:26:13 raspberrypi kernel: [11539.588939] usbcore: registered new interface driver uvcvideo
> Mar 13 00:26:13 raspberrypi kernel: [11539.588969] USB Video Class driver (1.1.1)

で、あとはこの非力なRaspberryPiを、安価ながら最強の(笑)ライブカメラ
に仕立ててみましょう。

GUI上でやるとそれだけでCPUパワーを持って行かれるので、コマンドライン
CUIで遊べるものを探します。

raspbianをインストール&起動後に

apt-cache search webcam

とすると、

> fswebcam – Tiny and flexible webcam program
> gmotionlive – A simple multipart/x-mixed-replace viewer
> libdecodeqr-dev – A C/C++ library for decoding QR code
> libdecodeqr-examples – Sample program in C/C++ library for decoding QR code
> libdecodeqr0 – A C/C++ library for decoding QR code
> libmimic-dev – A video codec for Mimic V2.x content (development files)
> libmimic-doc – A video codec for Mimic V2.x content (documentation)
> libmimic0 – A video codec for Mimic V2.x content
> python-libmimic – A video codec for Mimic V2.x content (python bindings)
> libwebcam0-dbg – Debug Symbols for the Webcam Library
> libwebcam0-dev – The Webcam Library
> libwebcam0 – The Webcam Library
> uvcdynctrl-data – Command line tool to control v4l2 devices
> uvcdynctrl-dbg – Debug Symbols for uvcdynctrl
> uvcdynctrl – Command line tool to control v4l2 devices
> minbif-common – IRC-to-other-IM-networks gateway using Pidgin library (common files)
> minbif-dbg – IRC-to-other-IM-networks gateway using Pidgin library (dbg)
> minbif-webcam – IRC-to-other-IM-networks gateway using Pidgin library (webcam)
> minbif – IRC-to-other-IM-networks gateway using Pidgin library
> pymissile – Control Marks and Spencer USB Missile Launcher
> qc-usb-source – source for the QuickCam Express driver
> qc-usb-utils – utility programs for the QuickCam Express driver
> uvccapture – USB UVC Video Class snapshot software
> webcamd – Capture images from video devices
> webcam – image grabber and uploader
> zbar-tools – bar code scanner and decoder (utilities)
> camstream – webcams および他のビデオデバイス用ツール集
> feh – imlib2 ベースの画像ビューア

と、いろいろ出てくるので、この中でCUIでも動かせるものをいくつか試す。

まぁすでに

『□VineでWEBCAM~時代は変わったな~』
http://linux.yebisu.jp/memo/389

でfswebcamとかffmpegあたりは試しているのですが、改めて。:-)

あ、RasPiに日本語フォントを入れてなかったら入れましょう。

apt-get -y install fonts-vlgothic fonts-ipafont fonts-ipaexfont

…これだと標準でIPAexFontになります。

・fswebcam

http://www21.atwiki.jp/snagplaces/pages/46.html
http://www.smiyasaka.com/fswebcam.html

apt-get -y install fswebcam

インストールできたら早速キャプチャしてみる。

fswebcam -d /dev/video0 \
   -p YUYV -D 2 -S 16 -r 640x480 \
   --jpeg 75 --line-colour '#FF000000' \
   --text-colour '#40FFFFFF' --banner-colour '#FF000000' \
   --title "漢字も打てますよ" \
   --font "/usr/share/fonts/truetype/vlgothic/VL-PGothic-Regular.ttf:12" \
   /var/tmp/output.jpg

以前はEUCでないとNGでしたが、UTF-8のままでも漢字でました。

・ffmpeg

http://linux.yebisu.jp/memo/389

これは面倒なので省略。motionをapt-getで入れるとffmpegも入ります。:-)

・webcam

http://www2s.biglobe.ne.jp/~sasihara/science/webcam.html

apt-get -y install webcam

インストールできたら設定ファイルを書く。

cat > ~/.webcam

----------
[grab]
device = /dev/video0
text = webcam %Y-%m-%d %H:%M:%S
infofile = filename
fg_red = 255
fg_green = 255
fg_blue = 255
width = 640
height = 480
delay = 10
wait = 2
#input = composite1
#norm = pal
#rotate = 0
top = 0
left = 0
bottom = -1
right = -1
quality = 75
trigger = 0
once = 1
#archive = /PATH_TO/live_%Y%m%d%H%M%S.jpg
archive = /var/tmp/output.jpg
----------

として、

webcam ~/.webcam

とすればOK。漢字は打てない。

・uvccapture

http://tomono.eleho.net/2012/10/06/3308/
http://www2.denshi.numazu-ct.ac.jp/mirsdoc2/mirsmg3d/osin/num0005a/0005.html
http://www2.denshi.numazu-ct.ac.jp/mirsdoc2/mirsmg3d/osin/num0006a/0006.html

apt-get -y install uvccapture

インストールできたら早速キャプチャしてみる。

> -v              Verbose
> -o<filename>    Output filename(default: snap.jpg)
> -d<device>      V4L2 Device(default: /dev/video0)
> -x<width>       Image Width(must be supported by device)(>960 activates YUYV capture)
> -y<height>      Image Height(must be supported by device)(>720 activates YUYV capture)
> -c<command>     Command to run after each image capture(executed as <command> <output_filename>)
> -t<integer>     Take continuous shots with <integer> seconds between them (0 for single shot)
> -q<percentage>  JPEG Quality Compression Level (activates YUYV capture)
> -r              Use read instead of mmap for image capture
> -w              Wait for capture command to finish before starting next capture
> -m              Toggles capture mode to YUYV capture
> Camera Settings:
> -B<integer>     Brightness
> -C<integer>     Contrast
> -S<integer>     Saturation
> -G<integer>     Gain

uvccapture -v \
   -o/var/tmp/output.jpg \
   -d/dev/video0 \
   -x640 \
   -y480 \
   -q75 \
   -m

・motion

http://www.bird-soft.net/mt/2009/06/linuxwebmotion.html

apt-get -y install motion

/etc/motion/motion.conf が設定ファイル…PostgreSQLはじめ、
DBともなにか連携できるらしい。

とはいえ、設定を変更するのはとりあえずは以下のパラメーター
くらいかな?

emacs /etc/motion/motion.conf

----------
# Start in daemon (background) mode and release terminal (default: off)
###daemon off
daemon on

# File to store the process ID, also called pid file. (default: not defined)
###process_id_file /var/run/motion/motion.pid
process_id_file /var/run/motion.pid

# V4L2_PIX_FMT_SN9C10X : 0  ‘S910’
# V4L2_PIX_FMT_SBGGR8  : 1  ‘BA81’
# V4L2_PIX_FMT_MJPEG   : 2  ‘MJPEG’
# V4L2_PIX_FMT_JPEG    : 3  ‘JPEG’
# V4L2_PIX_FMT_RGB24   : 4  ‘RGB3’
# V4L2_PIX_FMT_UYVY    : 5  ‘UYVY’
# V4L2_PIX_FMT_YUYV    : 6  ‘YUYV’
# V4L2_PIX_FMT_YUV422P : 7  ‘422P’
# V4L2_PIX_FMT_YUV420  : 8  ‘YU12’
###v4l2_palette 8
v4l2_palette 6

# Image width (pixels). Valid range: Camera dependent, default: 352
###width 320
width 640

# Image height (pixels). Valid range: Camera dependent, default: 288
###height 240
height 480

# Maximum number of frames to be captured per second.
# Valid range: 2-100. Default: 100 (almost no limit).
###framerate 2
framerate 5

# Output ‘normal’ pictures when motion is detected (default: on)
# Valid values: on, off, first, best, center
# When set to ‘first’, only the first picture of an event is saved.
# Picture with most motion of an event is saved when set to ‘best’.
# Picture with motion nearest center of picture is saved when set to ‘center’.
# Can be used as preview shot for the corresponding movie.
###output_normal on
output_normal off

# Use ffmpeg to encode mpeg movies in realtime (default: off)
###ffmpeg_cap_new on
ffmpeg_cap_new off

# 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 off
locate on

# Target base directory for pictures and films
# Recommended to use absolute path. (Default: current working directory)
###target_dir /tmp/motion
target_dir /var/tmp/motion

# The mini-http server listens to this port for requests (default: 0 = disabled)
###webcam_port 8081
webcam_port 8088

# Restrict webcam connections to localhost only (default: on)
###webcam_localhost on
webcam_localhost off
# TCP/IP port for the http server to listen on (default: 0 = disabled)
###control_port 8080
control_port 8089

# Restrict control connections to localhost only (default: on)
###control_localhost on
control_localhost off
----------

あとは実際に起動。

ちなみにdaemon offの状態で起動してみると、

motion /etc/motion/motion.conf

> # motion /etc/motion/motion.conf
> [0] Processing thread 0 – config file /etc/motion/motion.conf
> [0] Motion 3.2.12 Started
> [0] ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478784
> [0] Thread 1 is from /etc/motion/motion.conf
> [0] motion-httpd/3.2.12 running, accepting connections
> [0] motion-httpd: waiting for data on port TCP 8089
> [1] Thread 1 started
> [1] cap.driver: “uvcvideo”
> [1] cap.card: “USB2.0 PC Camera”
> [1] cap.bus_info: “usb-bcm2708_usb-1.2”
> [1] cap.capabilities=0x04000001
> [1] – VIDEO_CAPTURE
> [1] – STREAMING
> [1] Test palette YUYV (640×480)
> [1] Using palette YUYV (640×480) bytesperlines 1280 sizeimage 614400 colorspace 00000008
> [1] found control 0x00980900, “Brightness”, range -64,127
> [1]     “Brightness”, default -8193, current 0
> [1] found control 0x00980901, “Contrast”, range 0,95
> [1]     “Contrast”, default 57343, current 0
> [1] found control 0x00980902, “Saturation”, range 0,150
> [1]     “Saturation”, default 57343, current 135
> [1] found control 0x00980903, “Hue”, range -40,40
> [1]     “Hue”, default -8193, current 0
> [1] found control 0x00980910, “Gamma”, range 1,100
> [1]     “Gamma”, default 57343, current 1
> [1] mmap information:
> [1] frames=4
> [1] 0 length=614400
> [1] 1 length=614400
> [1] 2 length=614400
> [1] 3 length=614400
> [1] Using V4L2
> [1] Resizing pre_capture buffer to 1 items
> [1] Started stream webcam server in port 8088

こんな感じで起動するので、

http://raspberrypiのIPアドレス:8080/

のようにしてアクセス…だけど、IE8までは表示できないかも。

daemon inだと、

> # motion /etc/motion/motion.conf
> [0] Processing thread 0 – config file /etc/motion/motion.conf
> [0] Motion 3.2.12 Started
> [0] Motion going to daemon mode

としか出ない。:-)

・MJPG-streamer

http://armadillo.atmark-techno.com/howto/webcam-streaming
http://cozyattic.wordpress.com/2009/10/19/mjpg-streamer%E3%81%A7%E3%82%B9%E3%83%88%E3%83%AA%E3%83%BC%E3%83%9F%E3%83%B3%E3%82%B0%E9%85%8D%E4%BF%A1/

apt-get -y install subversion libjpeg8-dev imagemagick
cd /usr/src/
svn checkout https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer
cd mjpg-streamer/mjpg-streamer
make

できたら、

cp ./*.so /usr/lib/
cp ./mjpg_streamer /usr/bin/
mv ./www /var/

そしたら、あとは以下のようにして起動すればOK!?

mjpg_streamer \
   --input "input_uvc.so --device /dev/video0 --fps 5 --resolution 640x480 --yuv --quality 75" \
   --output "output_http.so --port 8088 --www /var/www --credentials user:password"

とすることで、YUYVモードで動かす。
(–yuvをとっても動くUVCカメラならはずしていいけど)

すると、

> MJPG Streamer Version: svn rev: 3:172
>  i: Using V4L2 device.: /dev/video0
>  i: Desired Resolution: 640 x 480
>  i: Frames Per Second.: 5
>  i: Format…………: YUV
>  i: JPEG Quality……: 75
> Adding control for Pan (relative)
> UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
> Adding control for Tilt (relative)
> UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
> Adding control for Pan Reset
> UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
> Adding control for Tilt Reset
> UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
> Adding control for Pan/tilt Reset
> UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
> Adding control for Focus (absolute)
> UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
> mapping control for Pan (relative)
> UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
> mapping control for Tilt (relative)
> UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
> mapping control for Pan Reset
> UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
> mapping control for Tilt Reset
> UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
> mapping control for Pan/tilt Reset
> UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
> mapping control for Focus (absolute)
> UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
> mapping control for LED1 Mode
> UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
> mapping control for LED1 Frequency
> UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
> mapping control for Disable video processing
> UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
> mapping control for Raw bits per pixel
> UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
>  o: www-folder-path…: /var/www/
>  o: HTTP TCP port…..: 8088
>  o: username:password.: user:password
>  o: commands……….: enabled

こんな感じできどうするので、あとは

http://raspberrypiのIPアドレス:8080/

のようにしてアクセス!!

 

Name of author

Name: admin

One Reply to “□RaspberryPiというかRaspbianで動くWebCAM監視カメラ(ライブカメラ)”

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA