树莓派+motion的网络摄像头

本文详细介绍了如何使用树莓派和motion软件搭建摄像头监控系统,包括环境搭建、摄像头操作、帧率调整及自动拍照功能关闭等步骤,帮助读者快速上手。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

学习记录

将树莓派USB摄像头拍摄的画面通过USB摄像头显示出来

设备环境

  1. 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

参考

  1. 官方配置文档:树莓派+motion 搭建摄像头监控系统
  2. 野生翻译: 树莓派+motion 搭建摄像头监控系统.
### 关于树莓派摄像头使用 Motion 进行参数配置 #### 安装 Motion 为了使树莓派能够利用摄像头捕捉动态并触发特定动作,需先安装 Motion。可以通过以下命令完成安装: ```bash sudo apt-get update sudo apt-get install motion ``` #### 启动与服务设置 安装完成后,应当启动 Motion 并将其设为开机自启的服务。 ```bash sudo systemctl start motion sudo systemctl enable motion ``` #### 修改配置文件 Motion 的主要配置位于 `/etc/motion/motion.conf` 文件内,在这里可以调整各种参数以满足不同的需求。下面是一些常用的配置项及其说明[^3]: - **宽高分辨率** - `width 640`: 设置捕获图像宽度。 - `height 480`: 设置捕获图像高度。 - **帧率控制** - `framerate 100`: 控制每秒最大帧数。 - **灵敏度调节** - `threshold 1500`: 设定变化像素数量阈值;超过此数值则认为发生了运动事件。 - **预览窗口显示与否** - `webcam_localhost off`: 是否允许远程访问网页摄像机流,默认仅限本地主机查看。 - **视频质量设定** - `quality 75`: 输出JPEG图片的质量百分比(范围:2到100),默认值为50%。 - **目标目录指定** - `target_dir /var/lib/motion`: 存储所拍摄的照片或录制的影片的位置。 对于更详细的参数列表以及具体含义,建议查阅官方文档获取最新最全的信息。修改完毕后保存更改,并重启 Motion 让新设置生效: ```bash sudo service motion restart ``` 通过上述步骤即可完成基本的 Motion 参数配置工作,从而让树莓派具备自动侦测物体移动的能力,并据此执行相应的操作如拍照记录等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值