Raspberry PiにWebカメラ
webカメラはelecomのUSB接続のやつを使ってみた。
https://qiita.com/henjiganai/items/b491e498d7d367306cd5
https://www.sys-link.jp/it/electronic-kit/raspberrypi/raspberrypi-004/
https://qiita.com/henjiganai/items/b491e498d7d367306cd5
https://www.sys-link.jp/it/electronic-kit/raspberrypi/raspberrypi-004/
rpi-updateはやってはいけない?
pi@raspberrypi1:/dev $ sudo rpi-update *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom *** Performing self-update *** Relaunching after update *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom *** We're running for the first time *** Backing up files (this will take a few minutes) *** Backing up firmware *** Backing up modules 5.4.79+ ############################################################# WARNING: This update bumps to rpi-5.10.y linux tree See: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=288234'rpi-update' should only be used if there is a specific reason to do so - for example, a request by a [[Raspberry Pi]] engineer or if you want to help the testing effort and are comfortable with restoring if there are regressions. DO NOT use 'rpi-update' as part of a regular update process. ############################################################## Would you like to proceed? (y/N) *** Downloading specific firmware revision (this will take a few minutes) % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 168 100 168 0 0 536 0 --:--:-- --:--:-- --:--:-- 538 100 119M 0 119M 0 0 1037k 0 --:--:-- 0:01:58 --:--:-- 937k *** Updating firmware *** Updating kernel modules *** depmod 5.10.5-v7l+ *** depmod 5.10.5-v8+ *** depmod 5.10.5-v7+ *** depmod 5.10.5+ *** Updating VideoCore libraries *** Using HardFP libraries *** Updating SDK *** Running ldconfig *** Storing current firmware revision *** Deleting downloaded files *** Syncing changes to disk *** If no errors appeared, your firmware was successfully updated to 67626d4d9bf319bbe36cb200f4297dcd77da559 *** A reboot is needed to activate the new firmware
警告を見ずにやってしまったが、まあいいか。
カメラの接続の確認
こうするらしい。
pi@raspberrypi1:~ $ ls /dev/video* /dev/video0 /dev/video10 /dev/video12 /dev/video14 /dev/video16 /dev/video1 /dev/video11 /dev/video13 /dev/video15
ここにvideo0があれば認識されているらしい。で、こうするらしい。
pi@raspberrypi1:~ $ lsusb Bus 001 Device 004: ID 056e:701a Elecom Co., Ltd Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub Bus 001 Device 001: ID 1d6b:0002 [[Linux]] Foundation 2.0 root hub
Device 004というのがElecomのUSBカメラらしい。
fswebcamのインストール
fsebcamというのはカメラで静止画を撮るコマンドらしい。カメラの動作の確認ができるらしい。
sudo apt-get install fswebcam
を実行してインストール後、
fswebcam /tmp/test.jpg
とすると撮影された静止画が保存される。ただ、実験に用いている初代ラズパイはCUI環境なので画像ファイルを見ることができないことにはたと気づいた。ftpで持ってくにしてもftpサーバがない。
ググるとfbiというコマンドでCUI環境で画像が見れるらしいが、これはラズパイのHDMI端子に接続されたディスプレイに直接画像を表示するものであって、リモートでは見ることができない。
というわけで静止画の確認は諦めたが、上のコマンドで確かにファイルは生成された。
MJPG-streamerのインストール
よくわからない。
sudo mkdir mjpg-streamer sudo cd mjpg-streamer # cmake、libjpeg8-devを取得 sudo apt-get install cmake libjpeg8-dev sudo git clone https://github.com/jacksonliam/mjpg-streamer.git # コンパイル cd mjpg-streamer/mjpg-streamer-experimental sudo make # コンパイル後のバイナリファイルを配置 sudo make install
そうすると/usr/local/libにmjpg-streamerというディレクトリが作られる。
pi@raspberrypi1:/usr/local/lib $ ls mjpg-streamer python2.7 python3.7
MJPG-streamerを動かす
下のようにした
pi@raspberrypi1:/usr/local/lib/mjpg-streamer $ sudo mjpg_streamer -o "/usr/local/lib/mjpg-streamer/output_http.so -w ./www -p 8080" -i "/usr/local/lib/mjpg-streamer/input_uvc.so -d /dev/video0 -r 640x480 -fps 3 -q 10 -y -n"
これでフレームレート3、サイズ640x480でhttpのポート8080にストリーミングされる。
MJPG Streamer Version: git rev: 5554f42c352ecfa7edaec6fc51e507afce605a34 i: Using V4L2 device.: /dev/video0 i: Desired Resolution: 640 x 480 i: Frames Per Second.: 3 i: Format............: YUYV i: JPEG Quality......: 10 i: TV-Norm...........: DEFAULT i: FPS coerced ......: from 3 to 2 o: www-folder-path......: ./www/ o: HTTP TCP port........: 8080 o: HTTP Listen Address..: (null) o: username:password....: disabled o: commands.............: enabled
ctrl+Cで終了する。
ストリーミング画像を見る
適当なブラウザでURLの所にhttp://192.168.11.50:8080/?action=streamと入れればストリーミング画像が見れる。VNCメディアプレイヤーでも動作が確認できた。
動作中にnmapでポートの空き具合を確認するとこうなった。
動作中にnmapでポートの空き具合を確認するとこうなった。
pi@raspberrypi4:~ $ nmap 192.168.11.50 Starting Nmap 7.70 ( https://nmap.org ) at 2021-01-11 14:05 JST Nmap scan report for 192.168.11.50 Host is up (0.015s latency). Not shown: 998 closed ports PORT STATE SERVICE 22/tcp open ssh 8080/tcp open http-proxy Nmap done: 1 IP address (1 host up) scanned in 1.54 seconds
8080がhttp-proxyとなっている。
起動スクリプトの作成と実行
いちいちいコマンドラインで長いコマンドを打つのを省略するため。
起動スクリプト
start_server.sh
#!/bin/sh PORT="8080" #ポート番号 ID="user" #ID PW="passward" #パスワード SIZE="640x480" #画面サイズ FRAMERATE="3" #フレームレート export LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer \ -i "input_uvc.so -fps $FRAMERATE -r $SIZE -d /dev/video0 -y -n" \ -o "output_http.so -w ./www -p $PORT -c $ID:$PW"
ストリーミングサーバの起動
$ sudo sh start_server.sh
以上