学习记录
将树莓派USB摄像头拍摄的画面通过USB摄像头显示出来
设备环境
- List item
搭建环境
首先安装motion。motion是Linux下一款开源的摄像头监控软件。
sudo apt-get install motion
接下来对motion进行配置
sudo vim /etc/default/motion
将no改为yes,保存退出
打开配置文件
sudo vim /etc/motion/motion.conf
开启后台运行模式(line 11)
daemon on
视频显示(line 89)
# Image width (pixels). Valid range: Camera dependent, default: 352
width 320
# Image height (pixels). Valid range: Camera dependent, default: 288
height 240
# Maximum number of frames to be captured per second.
# Valid range: 2-100. Default: 100 (almost no limit).
framerate 2
设置摄像头端口,建议将8081修改为其它数字,否则有可能出错(line 464)
stream_port 8085
关闭仅本地连接(line 477)
stream_localhost off
webcontrol设置(line 499)
# TCP/IP port for the http server to listen on (default: 0 = disabled)
webcontrol_port 8080
# Restrict control connections to localhost only (default: on)
webcontrol_localhost off
# Output for http server, select off to choose raw text plain (default: on)
webcontrol_html_output on
保存并退出
摄像头操作
开启摄像头
sudo motion
关闭摄像头
service motion stop
实测上面一句话没用。改用下面的命令关闭
sudo killall -TERM motion
最终结果
地址栏输入树莓派ip和端口号,在浏览器中观看视频。
例如:192.168.0.105:8085
各自输各自对应ip和端口号,不要按我的来。
焦距没有调,所以画面比较模糊。
帧率感人,卡成PPT。因为本身我的网不好,不知道是网的原因,还是摄像头的原因,还是树莓派的原因。
修改帧率
再次测试了一下,帧率低是自己的设置有问题
打开配置文件
sudo vim /etc/motion/motion.conf
修改最大帧数(line 95)
# Maximum number of frames to be captured per second.
# Valid range: 2-100. Default: 100 (almost no limit).
framerate 30
修改字节流的最大帧数
# Maximum framerate for stream streams (default: 1)
stream_maxrate 30
保存退出,重启。
画面跟我一起摇摆。
关闭自动拍照
关闭自动拍照(line 244)
# Output 'normal' pictures when motion is detected (default: on)
# Valid values: on, off, first, best, center
# When set to 'first', only the first picture of an event is saved.
# Picture with most motion of an event is saved when set to 'best'.
# Picture with motion nearest center of picture is saved when set to 'center'.
# Can be used as preview shot for the corresponding movie.
output_pictures off
参考
- 官方配置文档:树莓派+motion 搭建摄像头监控系统
- 野生翻译: 树莓派+motion 搭建摄像头监控系统.