Raspbian安装摄像头

1. 源由

家里闲置两块树莓派,打算做个WiFi视频流RTSP/RTP:

  • Raspberry Pi Zero W
  • Raspberry Pi 3B+

注:后续打算上天,帮我在模拟航模上拍点高清视频。

2. 摄像头

2.1 选型

本来想上一个热成像摄像头,看看夜景,奈何并非这么简单,而且价格也高。就不整那个玩意了。

大白天,我们选了两款:

  • 鱼眼 OV5647 130° 1.85mm 非夜视
    在这里插入图片描述

  • 树莓派原装 V2 IMX219 NoIR
    在这里插入图片描述

2.2 系统

妥妥的原生态系统bullseye,目前来说,兼容性是比较好的。系统安装参考:《Raspbian镜像无头烧录》

注:如果想使用其他系统,可以访问:raspios_lite armhf/arm64

2.3 安装

  • Raspberry Pi Zero W
    在这里插入图片描述

  • Raspberry Pi 3B+
    在这里插入图片描述

3. 配置&命令

3.1 命令

新系统已经不支持raspistillraspivid了,更多用的是libcamera

$ libcamera-
libcamera-hello  libcamera-jpeg   libcamera-raw    libcamera-still  libcamera-vid
  1. libcamera-hello: 一个简单的“ Hello World”应用程序,该应用程序启动了相机预览流并在屏幕上显示。
  2. libcamera-jpeg: 一个简单的应用程序来运行预览窗口,然后捕获高分辨率静止图像。
  3. libcamera-still: 更复杂的静止图像捕获应用程序,该应用程序模拟了Raspistill的更多特征。
  4. libcamera-vid: 视频捕获应用程序。
  5. libcamera-raw: 直接从传感器捕获原始(未加工的拜耳)框架的基本应用程序。

注:以前raspistill: command not found命令已经被逐渐淘汰,详见:raspios_armhf/release_notes.txt

2021-10-30:

  • New default camera subsystem based on libcamera
  • New camera demo applications (libcamera-still and libcamera-vid) have replaced raspistill and raspivid
  • Legacy camera subsystem removed from 64-bit RPi OS (still available on 32-bit)

3.2 配置

$ sudo nano /boot/config.txt
  • Step 1:将camera-auto-detect=1修改camera_auto_detect=0

  • Step 2:根据摄像头不同型号,添加dtoverlay驱动设置到/boot/config.txt文件中。

鱼眼 OV5647 130° 1.85mm 非夜视:dtoverlay=ov5647
树莓派原装 V2 IMX219 NoIR:dtoverlay=imx219

在这里插入图片描述

4. 测试

4.1 拍照

拍照正常,基本驱动应该就正常了,详细的指令可以参考:Pi5-IMX219, www.waveshare.com

4.1.1 libcamera-jpeg

  • 全像素JPEG拍照:
$ libcamera-jpeg -o test.jpg
  • 指定宽度高度拍照:
$ libcamera-jpeg -o test.jpg -t 2000 --width 640 --height 480
  • 指定曝光和增益拍照:// exposure 20ms, gain 1.5x
$ libcamera-jpeg -o test.jpg -t 2000 --shutter 20000 --gain 1.5
  • 指定EV补偿拍照:
$ libcamera-jpeg --ev -0.5 -o darker.jpg
$ libcamera-jpeg --ev 0 -o normal.jpg
$ libcamera-jpeg --ev 0.5 -o brighter.jpg

4.1.2 libcamera-still

  • 测试命令:
$ libcamera-still -o test.jpg
  • 不同编码格式拍照:
$ libcamera-still -e png -o test.png
$ libcamera-still -e bmp -o test.bmp
$ libcamera-still -e rgb -o test.data
$ libcamera-still -e yuv420 -o test.data
  • 原始数据保存:
$ libcamera-still -r -o test.jpg
  • 长时间曝光拍照:
$ libcamera-still -o long_exposure.jpg --shutter 100000000 --gain 1 --awbgains 1,1 --immediate

在这里插入图片描述

4.2 视频流

  • Step 1:安装vlc组件
$ sudo apt-get install vlc

4.2.1 RTSP流

  • Step 2:启动rtsp服务端
$ libcamera-vid -t 0 --inline -o - | cvlc stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/stream1}' :demux=h264
  • Step 3:启动VLC播放器

在这里插入图片描述

rtsp://192.168.1.201:8554/stream1
  • Step 4:确认结果

在这里插入图片描述

4.2.2 TCP流

  • Step 2:启动TCP服务端
$ libcamera-vid -t 0 --inline --listen -o tcp://0.0.0.0:8554
  • Step 3:启动VLC播放器

在这里插入图片描述

tcp/h264://192.168.1.201:8554
  • Step 4:确认结果

在这里插入图片描述

5. 实际效果

在这里插入图片描述
Ready for fly!!!

在这里插入图片描述

6. 参考资料

【1】Raspbian镜像无头烧录
【2】Pi5-IMX219, www.waveshare.com
【3】Introducing the Raspberry Pi Cameras

7. 附录

关于摄像头驱动问题需要谨慎面对,因为树莓派只有一个CSI摄像头可以连接,因此,配置文件中也只能有一个,如果出现多个可能会有问题。

$ libcamera-jpeg -o test.jpg
Preview window unavailable
[0:02:45.224902956] [843]  INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f
ERROR: *** no cameras available ***

$ dmesg|grep 5647
[   12.055937] ov5647 10-0036: Unsupported clock frequency: 24000000
[   12.055990] ov5647: probe of 10-0036 failed with error -22

$ vcgencmd get_camera
supported=1 detected=0, libcamera interfaces=1

以下配置时,OV5647驱动能正常识别摄像头。

$ cat /boot/config.txt  //截取部分输出
# Enable DRM VC4 V3D driver
camera_auto_detect=1
#dtoverlay=vc4-kms-v3d
max_framebuffers=2
dtoverlay=ov5647
#dtoverlay=ov5647,clock-frequency=24000000
#dtoverlay=imx219

vcgencmd get_camera该命令感觉没什么用,不管驱动有没有识别摄像头,detected=0

因此,别被这个带坑里了。

 $ dmesg|grep 5647
[    0.094969] platform 3f801000.csi: Fixed dependency cycle(s) with /soc/i2c0mux/i2c@1/ov5647@36
[   12.045831] ov5647 10-0036: Consider updating driver ov5647 to match on endpoints

$ vcgencmd get_camera
supported=1 detected=0, libcamera interfaces=1

这篇Ardu ov5467 1080P 5MP w/ Raspberry pi 3 using libcamera里面的部分内容还是值得一看的,可以相对明确的找出一些原因。

  • 0
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值