树莓派 调用摄像头
环境
树莓派3B+
系统升级到pi os 64bit 20241119版本;使用最新的pios,利用libcamera 库,才能调用最新的一些摄像头模组imx708.
摄像头:一代 OV5647,三代IMX708
系统配置
OV5647默认配置可以用,
cat /boot/firmware/config.txt
# For more options and information see
# http://rptl.io/configtxt
# Some settings may impact device functionality. See link above for details
# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# Additional overlays and parameters are documented
# /boot/firmware/overlays/README
# Automatically load overlays for detected cameras
camera_auto_detect=1
# Automatically load overlays for detected DSI displays
display_auto_detect=1
# Automatically load initramfs files, if found
auto_initramfs=1
# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2
# Don't have the firmware create an initial video= setting in cmdline.txt.
# Use the kernel's default instead.
disable_fw_kms_setup=1
# Run in 64-bit mode
arm_64bit=1
# Disable compensation for displays with overscan
disable_overscan=1
# Run as fast as firmware / board allows
arm_boost=1
[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1
[cm5]
dtoverlay=dwc2,dr_mode=host
[all]
IMX708是东莞微象摄像头
sudo nano /boot/firmware/config.txt
camera_auto_detect=1
改为
camera_auto_detect=0
最后添加
dtoverlay=imx708
sudo reboot
参考:IMX708摄像头在树莓派上操作方法_哔哩哔哩_bilibili
指令
libcamera-hello
这个是一个简单的“hello world" 程序,用来预览摄像头并将摄像头画面显示在屏幕上。
使用示例
libcamera-hello
拍摄一张全像素的JPEG图像
libcamera-jpeg -o test.jpg
libcamera-vid是一个视频录制程序, 默认使用的是树莓派的硬件H.264编码器。这个程序运行之后会在屏幕上显示一个预览窗口,同时将比特流编码输出到指定文件。比如,录制一个10s的视频。
libcamera-vid -t 10000 -o test.h264
如果要查看视频可以用vlc来进行播放
vlc test.h264
TCP视频流传输
可以使用TCp进行视频流传输, 树莓派端运行(server):
libcamera-vid -t 0 --inline --listen -o tcp://0.0.0.0:<port>
示例
libcamera-vid -t 0 --inline -o udp://192.168.1.101:5600
摄像头视频流显示的延迟大约几百ms
参考文档
liecamera使用指南,参考
模板:RPi Camera libcamera Guide - Waveshare Wiki