和我一起玩树莓派3B+--USB摄像头(八)

一、检测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:/# 

从上面的两个命令,第一个看出来设备中已经有video的设备了,
第二个 中 发现有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

二、安装视频监控

root@raspberrypi:~# sudo apt-get install motion

root@raspberrypi:~# apt-get update

#如果无法安装,请更换源
root@raspberrypi:~# sudo nano /etc/apt/sources.list
#内容为:
#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
# 安装监控
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

启动监控:

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)

http://192.168.1.118:8081/

监控

退出

root@raspberrypi:~# kill -9 2275
root@raspberrypi:~# netstat -apn|grep 8081
#视频与图像保存目录为:
root@raspberrypi:~# ls /var/lib/motion/
#删除内容
root@raspberrypi:~# rm -rf /var/lib/motion/

注意:800x600有些卡,默认为:352x288 640x480

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容