ページ更新: 2005-12-23 (金) (6367日前)

(2002.02.24 作成) (2005-04-18 リンク追加、目次の追加)

Che-ez! babeでWebカメラ

デジカメ「Che-ez! babe」でWeb Cameraします。
環境は Debian GNU/Linux 3.0 (Woody) kernel 2.4.17k6 です。

Che-ez! babe
cheezbabe.jpg

目次

[編集]

情報源 #

[編集]

カメラ #

Che-ez!party

Che-ez!babe

「Che-ez!」など低価格デジカメのNHJが自己破産 -2005/08/09
http://dc.watch.impress.co.jp/cda/other/2005/08/09/2079.html

[編集]

ドライバ #

SourceForge Project Info - linux-stv0680-usb-support

  • stv680 driver for video、pencam、pensnap

Linux USB

[編集]

ソフト #

vgrabbj - videostream grabber

  • tarとdebianパッケージあり。

pencam/pensnap - linux-stv0680-usb-support

他にもいろいろあるだろうが(特に動体検知)、あまり探してない。 (当時、UNIX USER誌(だと思う)のKylixの連載で動体検知があり、自分でも作ってみようと思ってたので……)

[編集]

導入記 #

散財日記 2001/12 (MAKOPiの散財紀行)

  • Che-ez! Spyz での例

Linux + Che-wz! SPY(Z)でストリーミング配信 (日替わり実験室)

2005-04-18 以下、wikiの「リンク元」から見つけたページ

Che-ez!spyz (stv680) (Mc.N Homepage SDK)

長編技術レポート(備忘録) : Che-ez! SPYZをLinuxのWebカメラにするゾ! (IburiWorks)

LinuxとWebカメラ (FrontPage - Ryutaroh)

ウェブカメラ(webcam)の部屋 (赤坂さんの家のページ)

自宅サーバでLiveカメラ (◇物理おもしろ.COM◇)

Linux + Che-ez! SPY(Z)でストリーミング配信(ハードウェア編) (日替わり実験室)

玄箱+USBカメラ=WEBカメラサーバ (.h2o2のお気楽日記)

複数端末を想定したシステム構成および,商品撮影時のカメラ制御について (mikilab-top page)

[編集]

手順 #

[編集]

ドライバのコンパイルの準備 #

kernel 2.4 が既に入っているとします。
usb関連の設定(modconf でモジュールを入れて……videodev(video4linux) も入れて、

modconf ではこういう階層にある

kernel/drivers/media/video
  videodev
kernel/usb/
 usbcore
 usb-ohci

/proc/usb ... がなかったので直して、

$ cat /etc/fstab | grep usb
none   /proc/bus/usb   usbdevfs  defaaults   0  0
$

kerhen-headers を入れて(一部のヘッダが kernel-source にはなかったので)、シンボリックリンクを貼って、(コレでいいのか?)

# apt-get install kernel-headers-2.4.17-k6
# cd /usr/src
# ln -s kernel-headers-2.4.17-k6 linux
[編集]

ドライバのコンパイルと試し #

SourceForge Project Info - linux-stv0680-usb-support から stv680 driver 0.25 を入手し、展開し、コンパイル、insmod する。

$ tar zxvf stv680-0.25.tar.gz
$ cd stv680-0.25
$ make
gcc -D__KERNEL__ -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2 
-fomit-frame-pointer -pipe   -march=i586 -malign-functions=4 
-fno-strict-aliasing -DMODULE -DMODVERSIONS 
-include /usr/src/linux/include/linux/modversions.h -c stv680.c -o stv680.o
stv680.c: In function `stv680_start_stream':
stv680.c:816: warning: implicit declaration of function `usb_fill_bulk_urb'

# su
# insmod ./stv680.o
./stv680.o: unresolved symbol usb_fill_bulk_urb

kernel 2.4.17 を使っているので、stv680.c の stv680_start_stream() の次の場所を変更して回避した。本来はkernelを確かめて必要なら再構築すべきだが。

$ diff stv680.c.old stv680.c
815c815
< #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 16)
---
> #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 17)

$ make
gcc -D__KERNEL__ -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2 
-fomit-frame-pointer -pipe   -march=i586 -malign-functions=4 
-fno-strict-aliasing -DMODULE -DMODVERSIONS 
-include /usr/src/linux/include/linux/modversions.h -c stv680.c -o stv680.o
$ su
# insmod ./stv680.o
#

make install する。

# make install
`stv680.o' -> `/lib/modules/2.4.17-k6/kernel/drivers/usb/stv680.o'
depmod -a
# insmod stv680
Using /lib/modules/2.4.17-k6/kernel/drivers/usb/stv680.o
#
[編集]

ドライバの動作確認、デバイスの作成、USBの挙動の確認 #

/var/log/syslog を監視しながら、USBに挿す

$ tail -f /var/log/syslog

Feb 17 21:57:08 koca kernel: hub.c: USB new device connect on bus1/1, 
assigned device number 4
Feb 17 21:57:08 koca kernel: stv680.c: [stv680_probe:1576] STV(i): 
STV0680 camera found.
Feb 17 21:57:08 koca kernel: stv680.c: [stv680_probe:1604] STV(i): 
registered new video device: video0
Feb 17 21:57:08 koca usbmgr[834]: vendor:0x553 product:0x202
Feb 17 21:57:08 koca usbmgr[834]: class:0xff subclass:0x0 protocol:0x0
Feb 17 21:57:08 koca usbmgr[834]: USB device isn't matched the configuration

/dev/video0 と /dev/video を作って、

# mknod /dev/video0 c 81 0
# cd /dev
# ln -s video0 video
# chown root:video video0
# chown root:video video

カメラを繋いで、lsusb の結果を見る。

# lsusb

(以下、カメラの情報のみ抜粋)

Bus 001 Device 007: ID 0553:0202 VLSI Vision Ltd.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x0553 VLSI Vision Ltd.
  idProduct          0x0202
  bcdDevice            0.00
  iManufacturer           1 STMicroelectronics
  iProduct                2 USB Dual-mode Camera
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xa0
      Remote Wakeup
    MaxPower               70mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               none
        wMaxPacketSize         64
        bInterval               0
  Language IDs: (length=14)
     0409 English(US)
     040c French(French)
     0407 German(German)
     0410 Italian(Italian)
     0c0a Spanish(Modern)
     0416 Po rtugese(Portugese) 

カメラを繋いで、/proc/vide/stv680/video0 を見てみる。

$ cat /proc/video/stv680/video0
driver_version  : v0.25
model           : STV0680
in use          : no
streaming       : no
num_frames      : 2
Current size    : 0x0
swapRGB         : (auto) off
Palette         : 0
Frames total    : 0
Frames read     : 0
Packets dropped : 0
Decoding Errors : 0
[編集]

キャプチャ #

動作確認のために、手頃なキャプチャ用ソフトを探して、入れる。(vgrabbj、motion)

# apt-cache search webcam
came - Rewrite of xawtv webcam app using imlib2
camstream - collection of tools for webcams and other video-devices
cqcam - Color QuickCam (PC/Parallel) control program
feh - imlib2 based image viewer
gkrellkam - GKrellM plugin that displays a periodically updating image
gqcam - GTK Webcam control
motion - V4L Capture Program supporting Movement Detection
qce-source - source code for QuickCam Express kernel module
vgrabbj - grabs a image from a camera and puts it in jpg/png format
webcam - capture and upload images

# apt-get install webcam vgrabbj motion

vgrabbj はこういう風に使う。-S はSwitch BGR colormap to RGB colormap (try if colors are odd) だそうだ。
(2005-04-18 補足。いまはアプリケーションではなく、ドライバ stv680のオプションで入れ替えられるようだ)

$ vgrabbj -S -f test.jpeg
[編集]

CGIで画像を転送する #

まずは、手元のLinux機(Che-ez! babeを繋ぐ) で画像を提供できるようにする。

/etc/groups の video に www-data を足して、grpconv (addgrpあたりでできたっけ?)

# grep video /etc/group
video:x:44:www-data

# grpconv

vgrabbj を呼ぶcgiを作って……これでブラウザから表示できるようになる。

#!/usr/bin/perl

use strict;
use FileHandle;

my $temp= "./camera.$$.jpeg";

system "/usr/bin/vgrabbj -S -f $temp > /dev/null 2>&1";

if( open JPEG, $temp ) {
    my $buffer;
    print "Content-Length: ", -s JPEG, "\n";
    print "Content-Type: image/jpeg\n";
    print "Pragma: nocache\n";
    print "Refresh: 15\n";
    print "\n";
    print $buffer while read JPEG, $buffer, 4096;
    close JPEG;
}
close STDOUT;

unlink $temp if -e $temp;

exit;

(2002.09.02補足。vgrabbj 0.9.1-1(debian testing) の場合、/etc/vgrabbj.conf に設定あり。タイムスタンプ設定は UseTimeStamp On、書式は man strftimeすれば判る)

次に、discypus.jp からこのCGIにアクセスするようにする。こちらもCGI。これでdiscypus.jpで画像を表示できる。
(2005-04-18補足。もちろん、こんなコトせずに手元のLinuxPCからdiscypus.jpにftpした方が楽だ。 でもnsupdateでホストを登録で自前のDynamicDNSしてるので遊んでみたかったのだ)

#!/usr/bin/perl

use strict;
use LWP::Simple;
use FileHandle;

my $page = get 'カメラを繋いだPCのURIをココに書く';

print "Content-Length: ", length $page, "\n";
print "Content-Type: image/jpeg\n";
print "Pragma: nocache\n";
print "Refresh: 15\n";
print "\n";
print $page;

exit;

なお、運用時にはCGIじゃなくてcronで定期的に処理する予定。
ImageMagick (perlmagick) でサムネールなどを作ったり、ノイズキャンセル(レンズに蓋をしたときの画像を引き算すれば、暗部ノイズがキャンセルできる)したり、できればいいなあ。

[編集]

pencam/pensnap を入れてみる (作成中) #

SourceForge Project Info - linux-stv0680-usb-support のpencam/pensnap で遊んでみる。

pencam2-0.65

$ make
gcc -g -O2  -I/usr/include -Wall  -c pencam2.c -o pencam2.o
gcc -g -O2  -I/usr/include -Wall  -c pencam2-misc.c -o pencam2-misc.o
pencam2-misc.c: In function `common_do_function':
pencam2-misc.c:700: warning: use of `l' length character with `f' type character
pencam2-misc.c:708: warning: use of `l' length character with `f' type character
gcc -g -O2  -I/usr/include -Wall  -c pensnap2.c -o pensnap2.o
gcc -g -O2  -I/usr/include -Wall -c bayer.c -o bayer.o
gcc -g -O2  -I/usr/include -Wall -c unsharp.c -o unsharp.o
gcc -g -O2  -I/usr/include -Wall -c sharpen.c -o sharpen.o
gcc -g -O2  -I/usr/include -Wall -c saturate.c -o saturate.o
gcc -g -O2  -I/usr/include -Wall *.o  -o pencam2 -L/usr/lib -lusb -lm

# ./pencam2
 usb_claim_interface error
 usb_claim_interface error

 *  *  *  *  *   PENCAM2 ver 0.65 for STV0680 usb cameras   *  *  *  *  *

 STV Camera @     Camera Pictures     Firmware     ASIC rev     Sensor ID
   001:034               0              1.00         7.60         410.6
 *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
 Supported formats: CIF (352x288)    QCIF (176x144)
 *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

 YOUR CHOICES ARE:  (NOTE: choices are case sensitive)

 NOTE: /root/.pencam2rc file is NOT present.
 Press 'w' to create file now.

     C = PenCam functions and settings

     S = PenSnap functions and settings

     D = Load default values

     q = Quit.

 Enter your choice:

pensnap-0.21

$ make
gcc -g -O2  -I/usr/include -Wall  -c pensnap.c -o pensnap.o
gcc -g -O2  -I/usr/include -Wall -c bayer.c -o bayer.o
gcc -g -O2  -I/usr/include -Wall -c sharpen.c -o sharpen.o
gcc -g -O2  -I/usr/include -Wall -c saturate.c -o saturate.o
gcc -g -O2  -I/usr/include -Wall pensnap.o bayer.o  sharpen.o saturate.o -o pensna
p -L/usr/local/lib -lusb -lm

# ./pensnap
 usb_claim_interface error
 usb_claim_interface error

 *  *  *  *  *   PENSNAP ver 0.21 for STV0680 usb cameras    *  *  *  *
 STV Camera @    Camera Pictures     Firmware     ASIC rev    Sensor ID
   001:037              0              1.00         7.60        410.6
 *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
 Supported formats: CIF (352x288)    QCIF (176x144)
 *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *
 YOUR CHOICES ARE:
 p = Change the path name (/root/)

 f = Change the filename  (snapshot)

 l = Toggle Gamma correction-White balance (Auto Select)

 c = Toggle picture format (CIF)          b = Decrease brightness (1.00)

 t = Toggle sharpening filter (ON @ 66%)  g = Change sharpen percent

 s = Toggle saturate filter (ON @ 50%)    m = Change saturate percent

 d = Change the time delay (  60 sec)     i = Toggle camera beep (ON)

 q = quit.     z = start autosnap   x = stop autosnap.

 Enter your choice:  Press 'q' again to confirm: