一蚁袭、檢測USB攝像頭
插好USB攝像頭
輸入以下命令:
root@raspberrypi:/# ls -l /dev/video*
crw-rw----+ 1 root video 81, 0 Apr 10 07:50 /dev/video0
root@raspberrypi:/# lsusb
Bus 001 Device 006: ID 1908:2310 GEMBIRD
Bus 001 Device 004: ID 29a8:1701
Bus 001 Device 005: ID 0424:7800 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
root@raspberrypi:/#
從上面的兩個命令,第一個看出來設備中已經(jīng)有video的設備了,
第二個 中 發(fā)現(xiàn)有Sony Playstation Eye 俏扩。這兩個任何一個都說明了USB攝像頭被樹莓派檢測到了
二糜工、用USB Webcam拍照片
要安裝fswebcam,這是一款小型攝像頭程序录淡。你可以直接通過Raspbian的倉庫來安裝fswebcam捌木。
root@raspberrypi:/# sudo apt-get install fswebcam
Reading package lists... Done
Building dependency tree
Reading state information... Done
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://mirrors.nju.edu.cn/raspbian/raspbian stretch/main armhf fswebcam armhf 20140113-1 [44.0 kB]
Fetched 44.0 kB in 11s (3,931 B/s)
Selecting previously unselected package fswebcam.
(Reading database ... 115448 files and directories currently installed.)
Preparing to unpack .../fswebcam_20140113-1_armhf.deb ...
Unpacking fswebcam (20140113-1) ...
Setting up fswebcam (20140113-1) ...
Processing triggers for man-db (2.7.6.1-2) ...
fswebcam安裝完成后,在終端中運行下面的命令來抓去一張來自攝像頭的照片:
root@raspberrypi:/# fswebcam --no-banner -r 640x480 image.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
--- Capturing frame...
Captured frame in 0.00 seconds.
--- Processing captured image...
Disabling banner.
Writing JPEG image to 'image.jpg'.
# 查看圖片
root@raspberrypi:/# ls image.jpg
image.jpg
命令:
fswebcam -S 10 image.jpg
二嫉戚、安裝視頻監(jiān)控
root@raspberrypi:~# sudo apt-get install motion
root@raspberrypi:~# apt-get update
#如果無法安裝刨裆,請更換源
root@raspberrypi:~# sudo nano /etc/apt/sources.list
#內(nèi)容為:
#deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
#更換源后要重新update
root@raspberrypi:~# sudo apt-get update
# 安裝監(jiān)控
root@raspberrypi:~# sudo apt-get install motion
#然后就是修改motion的配置:
root@raspberrypi:~# sudo nano /etc/motion/motion.conf
#deamon off 改成 on
# Start in daemon (background) mode and release terminal (default: off)
daemon on
#設置分辨率
# Image width (pixels). Valid range: Camera dependent, default: 352
width 800
# Image height (pixels). Valid range: Camera dependent, default: 288
height 600
#on修改成off:
# Restrict stream connections to localhost only (default: on)
stream_localhost off
#on修改成off:
# Restrict control connections to localhost only (default: on)
webcontrol_localhost off
root@raspberrypi:~# sudo nano /etc/default/motion
# set to 'yes' to enable the motion daemon
#no修改成yes:
start_motion_daemon=yes
啟動監(jiān)控:
root@raspberrypi:~# sudo motion
[0:motion] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion/motion.conf
[0:motion] [NTC] [ALL] motion_startup: Motion 4.0 Started
[0:motion] [NTC] [ALL] create_path: creating directory /var/log/motion
[0:motion] [NTC] [ALL] motion_startup: Logging to file (/var/log/motion/motion.log)
退出
root@raspberrypi:~# kill -9 2275
root@raspberrypi:~# netstat -apn|grep 8081
#視頻與圖像保存目錄為:
root@raspberrypi:~# ls /var/lib/motion/
#刪除內(nèi)容
root@raspberrypi:~# rm -rf /var/lib/motion/
注意:800x600有些卡,默認為:352x288 640x480