树莓派USB摄像头开发—fswebcam、motion
一、简介
fswebcam 这是一款小型摄像头程序官网,则可以很好地支持 USB 摄像头。
二、详细步骤
插好USB摄像头,输入以下指令。
- ls -l /dev/video*
- lsusb
从上面的两个命令,第一个看出来设备中已经有video的设备了,
第二个 中 发现有Sony Playstation Eye 。这两个任何一个都说明了USB摄像头被树莓派检测到了。
三、安装视频监控
- apt-get update
- 如果无法安装,请更换源: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:sudo apt-get update
- 安装监控:sudo apt-get install motion
- 修改motion的配置: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 - sudo nano /etc/default/motion
#no修改成yes:
start_motion_daemon=yes
四、启动监控:
- sudo motion
- http://192.168.1.118:8081/
五、退出视频监控
- kill -9 2275
- netstat -apn|grep 8081
- 视频与图像保存目录为:ls /var/lib/motion/
- 删除内容:rm -rf /var/lib/motion/
- 注意:800x600有些卡,默认为:352x288 640x480。
六、用USB Webcam拍照片
要安装fswebcam,这是一款小型摄像头程序。你可以直接通过Raspbian的仓库来安装fswebcam。
- sudo apt-get install fswebcam
- fswebcam安装完成后,在终端中运行下面的命令来抓去一张来自摄像头的照片:
fswebcam --no-banner -r 640x480 image.jpg:-r 指定图片的分辨率,最后的是照片保存的路径。
fswebcam -S 10 image.jpg: -S 参数来跳过前面几帧解决。 - 查看图片:ls image.jpg