树莓派4B配置usb摄像头

文章目录

    • 使用lsusb查看usb设备
    • 安装motion 并且修改motion文件
    • 修改motion.conf
    • 启动命令
    • 访问地址,默认端口8081
    • 摄像头卡顿解决
    • 关闭命令
    • 启动命令
    • 接入MotionEye
    • 接入homeassistant
    • 小结


使用usb摄像头做监控
我这里使用的摄像头是 急速B18s
捕获的画质分别为:640 x 480,352 x 288,320 x 240

使用lsusb查看usb设备

在这里插入图片描述

我这里用的usb2.0的口

安装motion 并且修改motion文件

sudo apt-get install motion
sudo nano /etc/default/motion
把文件中 "start_motion_daemon=no" 改为yes

修改motion.conf

daemon on  #off改成on
width 640  
height 480
framerate 60 #这个代表帧率
stream_localhost off

启动命令

sudo motion

访问地址,默认端口8081

http://[树莓派地址]:8081/

摄像头卡顿解决

修改stream_maxrate值,1到100之间自己尝试把,我测试80感觉听流畅的

sudo nano /etc/motion/motion.confstream_maxrate  80

关闭命令

sudo killall -TERM motion

启动命令

sudo motion

接入MotionEye

我这采用的是docker安装

sudo docker run --name=motioneye  \
  -p 8765:8765 \
  --hostname=motioneye \
  -v /etc/localtime:/etc/localtime:ro \
  -v /etc/motioneye:/etc/motioneye \
  -v /var/lib/motioneye:/var/lib/motioneye \
  --restart=always \
  --detach=true \
  ccrisan/motioneye:master-armhf

默认账号:admin,密码空
访问地址:http://[树莓派地址]:8765/
树莓派4B配置usb摄像头_第1张图片
登录后添加网络摄像头
树莓派4B配置usb摄像头_第2张图片
添加完成后,就可以看到监控了

看到监控视频后,别忘记,修改帧率
树莓派4B配置usb摄像头_第3张图片
拖动到最大值

接入homeassistant

修改configuration.yaml配置文件
添加一下内容

# 监控
camera:
  - platform: generic
    name: 摄像头  
    still_image_url: http://{ip}:8765/picture/1/current/
    username: admin
    framerate: 30
# 移动监测
binary_sensor:
  - platform: ffmpeg_motion
    input: http://{ip}:8081/
    #changes: 3 //这个参数调整移动侦测灵敏度,值越小越灵敏。
    name: 移动侦测

添加完成后,重启你的homeassistant

从实体中添加卡片树莓派4B配置usb摄像头_第4张图片
添加完成后就会显示在你的ha页面中
树莓派4B配置usb摄像头_第5张图片
点击可以放大预览
树莓派4B配置usb摄像头_第6张图片
我们继续添加移动侦测
树莓派4B配置usb摄像头_第7张图片
我这里将移动侦测添加到顶部的徽章中,方便查看

小结

关于homeassistant接入摄像头这块的文档确实很少,在接入这块的时候,碰到一些问题,之前用stream_source的方式接入,图像是可以出来,但是开启预览后,发现一个问题,就是流量会一直跑,回来发现是这块开启请求后,预览关闭后,请求还是会一直发,最终用still_image_url,解决的这个问题,这里简单小记一下

你可能感兴趣的:(树莓派不同玩法,物联网,经验分享,linux)