本文章只适用于 CSI 摄像头,对于 USB 摄像头的解决方法可以参考别人的这篇:
树莓派4B无法使用raspistill命令:raspistill: command not found
使用树莓派4B摄像头时出现问题:
pi@raspberrypi:~ $ raspistill
-bash: raspistill: command not found
关于这个问题,网上好像有些说法
目前(4代树莓派、Debian10以及以后)raspistill
命令已经被逐渐遗弃
树莓派官方在 2021-10-30 Release Note 中提到,删除了原来的驱动支持:
- New default camera subsystem based on libcamera(基于libcamera的新默认摄像机子系统)
- New camera demo applications (libcamera-still and libcamera-vid) have replaced raspistill and raspivid
(新的相机演示应用程序(libcamera-Still和libcamera-vid)取代了raspistill和raspivid)- Legacy camera subsystem removed from 64-bit RPi OS (still available on 32-bit)
(从64位RPI OS中删除的旧摄像头子系统(仍在32位上可用)
意思就是新系统已经不支持raspistill
和raspivid
了,更多用的是libcamera
关于 libcamera
:
是一个旨在直接从Linux操作系统支持复杂的相机系统
的软件库。对于Raspberry Pi,它使我们能够直接从在ARM处理器上运行的开源代码驱动相机系统。
- libcamera-hello一个简单的“ Hello World”应用程序,该应用程序启动了相机预览流并在屏幕上显示。
- libcamera-jpeg一个简单的应用程序来运行预览窗口,然后捕获高分辨率静止图像。
- libcamera-still更复杂的静止图像捕获应用程序,该应用程序模拟了Raspistill的更多特征。
- libcamera-vid视频捕获应用程序。
- libcamera-raw直接从传感器捕获原始(未加工的拜耳)框架的基本应用程序。
更多libcamera的教程:官网链接
这里我们使用几个简单的libcamera命令进行截图:
1、libcamera-hello
2、libcamera-still -e png -o test.png
3、libcamera-jpeg -o test.jpg
查看当前目录下是否有test.jpg即可
一些踩坑经历
踩坑一:使用libcamera-hello后报错
ERROR: the system appears to be configured for the legacy camera stack:
解决方法:根据自己摄像头不同的模块 添加
dtoverlay
到
/boot/config.txt
文件
比如我就在/boot/config.txt添加
dtoverlay=imx219
,重启即可。
踩坑二 :no cameras available
pi@raspberrypi:~ $ libcamera-still -o test.jpg
Preview window unavailable
[0:11:14.538555624] [3381] INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3548-a11d63f9
ERROR: *** no cameras available ***
pi@raspberrypi:~ $ vcgencmd get_camera
supported=1 detected=0, libcamera interfaces=1发现detected为0,树莓派摄像头没连接上(估计是不稳定),重接重启。还是不行
解决办法:让树莓派重新加载V4L2驱动
1.修改/boot/config.txtroot@raspberrypi:~ # sudo nano /boot/config.txt
注释掉原来的摄像头自动检测语句,并添加"start_x=1"和"gpu_mem=128"
#camera_auto_detect=1
gpu_mem=128
start_x=12.修改/etc/modules
root@raspberrypi:~ # sudo nano /etc/modules
在最后面添加bcm2835-v4l2 3.重启树莓派,再次运行vcgencmd get_camera,应该会返回
supported=1 detected=1
参考链接:
- https://downloads.raspberrypi.org/raspios_armhf/release_notes.txt
- STICKY: Raspberry Pi OS (64 bit) beta test version feedback - Page 14 - Raspberry Pi Forums
- ERROR: *** no cameras available *** · Issue #168 · raspberrypi/libcamera-apps (github.com)