還有一個簡單方法,安裝fswebcam這個套件。
sudo apt-get install fswebcam
安裝過程大致上長這樣
pi@boywhy-pi2:~ $ sudo apt-get install fswebcam
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
pypy-upstream-doc wiringpi
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
fswebcam
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 44.0 kB of archives.
After this operation, 105 kB of additional disk space will be used.
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main fswebcam armhf 20140113-1 [44.0 kB]
Fetched 44.0 kB in 1s (35.9 kB/s)
Selecting previously unselected package fswebcam.
(Reading database ... 126790 files and directories currently installed.)
Preparing to unpack .../fswebcam_20140113-1_armhf.deb ...
Unpacking fswebcam (20140113-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up fswebcam (20140113-1) ...
pi@boywhy-pi2:~ $
拍一張,存成test.jpg (採用預設的解析度,大概是320*240 左右)
fswebcam test.jpg
指定拍照解析度(如果Webcam不支援的話,fswebcam會自動調整成最接近的解析度)
fswebcam -r 1280x720 image2.jpg
訊息大致上長這個樣子,注意 Adjusting resolution from 1024x720 to 640x480. 代表相機不支援1024x720,被強制改成640x480了
pi@boywhy-pi2:~ $ fswebcam -p YUYV -r 1024x720 test.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 1024x720 to 640x480.
--- Capturing frame...
Captured frame in 0.00 seconds.
--- Processing captured image...
Writing JPEG image to 'test.jpg'.
pi@boywhy-pi2:~ $
以上拍照後,相片上都會有個banner寫著拍照時間等等,如果不要的話,可以加上
--no-banner這個參數,相片就不會有多餘的資訊被打上去。
fswebcam -r 1280x720 --no-banner image3.jpg
如果拍照出來是黑黑的一片,注意一下是否有發生如下的訊息
GD Error: gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file:
俺試了2支Webcam,羅技C310 是OK的,但是C 170 就會出現這個錯誤訊息。
俺查詢了相關資料後,做了一個嘗試,改變 palette format 為YUYV後正常,
推測應該是Webcam硬體支援上的問題。
pi@boywhy-pi2:~ $ fswebcam -p YUYV test.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
Adjusting resolution from 384x288 to 352x288.
--- Capturing frame...
Captured frame in 0.00 seconds.
--- Processing captured image...
Writing JPEG image to 'test.jpg'.
pi@boywhy-pi2:~ $
正常取得照片
參考資料:
USING A STANDARD USB WEBCAM
沒有留言:
張貼留言