昨天晚上在搗鼓樹莓派的時候,發現Pi Camera V2插上去無法工作:
vcgencmd get_camera
#返回以下信息
supported=0 detected=0
運行libcamera-hello后,返回以下信息
libcamera-hello
libEGL warning: DRI2: failed to authenticate
[0:01:09.134776795] [1082] INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3156-f4070274
[0:01:09.223517004] [1082] INFO Camera camera.cpp:937 configuring streams: (0) 1640x1232-YUV420
[0:01:09.223789018] [1096] INFO RPI raspberrypi.cpp:122 Mode: 3280x2464 fmt RG10 Score: 2218 (best 2218)
[0:01:09.223941873] [1096] INFO RPI raspberrypi.cpp:122 Mode: 1920x1080 fmt RG10 Score: 2041.48 (best 2041.48)
[0:01:09.224046189] [1096] INFO RPI raspberrypi.cpp:122 Mode: 1640x1232 fmt RG10 Score: 1500 (best 1500)
[0:01:09.224142537] [1096] INFO RPI raspberrypi.cpp:122 Mode: 640x480 fmt RG10 Score: 5004.81 (best 1500)
[0:01:09.224241489] [1096] INFO RPI raspberrypi.cpp:122 Mode: 3280x2464 fmt pRAA Score: 1718 (best 1500)
[0:01:09.224337889] [1096] INFO RPI raspberrypi.cpp:122 Mode: 1920x1080 fmt pRAA Score: 1541.48 (best 1500)
[0:01:09.224436633] [1096] INFO RPI raspberrypi.cpp:122 Mode: 1640x1232 fmt pRAA Score: 1000 (best 1000)
[0:01:09.224531835] [1096] INFO RPI raspberrypi.cpp:122 Mode: 640x480 fmt pRAA Score: 4504.81 (best 1000)
[0:01:09.224632245] [1096] INFO RPI raspberrypi.cpp:122 Mode: 3280x2464 fmt RGGB Score: 3218 (best 1000)
[0:01:09.224728020] [1096] INFO RPI raspberrypi.cpp:122 Mode: 1920x1080 fmt RGGB Score: 3041.48 (best 1000)
[0:01:09.224824420] [1096] INFO RPI raspberrypi.cpp:122 Mode: 1640x1232 fmt RGGB Score: 2500 (best 1000)
[0:01:09.224918268] [1096] INFO RPI raspberrypi.cpp:122 Mode: 640x480 fmt RGGB Score: 6004.81 (best 1000)
[0:01:09.225191636] [1096] INFO RPI raspberrypi.cpp:620 Sensor: /base/soc/i2c0mux/i2c@1/imx219@10 - Selected mode: 1640x1232-pRAA
[0:01:09.277446418] [1100] INFO IPARPI raspberrypi.cpp:626 Request ctrl: Saturation = 1.000000
[0:01:09.277623803] [1100] INFO IPARPI raspberrypi.cpp:626 Request ctrl: Contrast = 1.000000
[0:01:09.277684841] [1100] INFO IPARPI raspberrypi.cpp:626 Request ctrl: Brightness = 0.000000
[0:01:09.277736869] [1100] INFO IPARPI raspberrypi.cpp:626 Request ctrl: AwbMode = 0
[0:01:09.277788896] [1100] INFO IPARPI raspberrypi.cpp:626 Request ctrl: Sharpness = 1.000000
[0:01:09.277843945] [1100] INFO IPARPI raspberrypi.cpp:626 Request ctrl: ExposureValue = 0.000000
[0:01:09.277898785] [1100] INFO IPARPI raspberrypi.cpp:626 Request ctrl: AeExposureMode = 0
[0:01:09.277947168] [1100] INFO IPARPI raspberrypi.cpp:626 Request ctrl: FrameDurationLimits = [ 33333, 33333 ]
[0:01:09.278008205] [1100] INFO IPARPI raspberrypi.cpp:626 Request ctrl: AeMeteringMode = 0
[0:01:09.278055234] [1100] INFO IPARPI raspberrypi.cpp:626 Request ctrl: NoiseReductionMode = 3
[0:01:09.279092094] [1096] INFO RPISTREAM rpi_stream.cpp:122 No buffers available for ISP Output0
[0:01:09.279279114] [1096] INFO RPISTREAM rpi_stream.cpp:122 No buffers available for ISP Output0
[0:01:09.279357494] [1096] INFO RPISTREAM rpi_stream.cpp:122 No buffers available for ISP Output0
[0:01:09.369502717] [1096] INFO RPI raspberrypi.cpp:1636 Dropping frame at the request of the IPA (6 left)
[0:01:09.407055783] [1096] INFO RPI raspberrypi.cpp:1636 Dropping frame at the request of the IPA (5 left)
[0:01:09.441079179] [1096] INFO RPI raspberrypi.cpp:1636 Dropping frame at the request of the IPA (4 left)
[0:01:09.471882313] [1096] INFO RPI raspberrypi.cpp:1636 Dropping frame at the request of the IPA (3 left)
[0:01:09.506164964] [1096] INFO RPI raspberrypi.cpp:1636 Dropping frame at the request of the IPA (2 left)
[0:01:09.538106201] [1096] INFO RPI raspberrypi.cpp:1636 Dropping frame at the request of the IPA (1 left)
[0:01:09.570362367] [1096] INFO RPI raspberrypi.cpp:1636 Dropping frame at the request of the IPA (0 left)
terminate called after throwing an instance of 'std::runtime_error'
what(): failed to import fd 19
Aborted
在確認raspi-config里Camera Enabled之后,還是無法解決。
經過搜索,貌似是因為64bit下MMAL問題,導致無法正常使用攝像頭,
且樹莓派官方在 2021-10-30 Release Note 中提到,刪除了原來的驅動支持:
- 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)
以下是解決辦法:
1.修改/boot/config.txt
root@raspberrypi:~ # sudo nano /boot/config.txt
...
#注釋掉原來的攝像頭自動檢測語句,並添加"start_x=1"和"gpu_mem=128"
#camera_auto_detect=1
gpu_mem=128
start_x=1
...
該操作會讓樹莓派重新加載老版本的V4L2驅動
2.修改/etc/modules
root@raspberrypi:~ # sudo nano /etc/modules
...
#在最后面添加
bcm2835-v4l2
...
3.重啟樹莓派
此時再次運行
vcgencmd get_camera
#應該會返回
supported=1 detected=1
此時攝像頭可通過ffplay、fswebcam等正常使用
fswebcam /dev/video0 -r 640x480 ~/test.jpg
#or
ffplay -f v4l2 -framerate 60 -video_size hd720 /dev/video0
需要注意,目前無法通過libcamera訪問,會提示no camera available
參考鏈接:
1.qaza2008:樹莓派4B 入門指導-- raspberry pi OS version : 2021/10/30 , Based on Debian version 11 (bullseye)
2.ourkix:樹莓派4B ubuntu20.04 驅動pi camera模塊
3.slimhazard:Re: STICKY: Raspberry Pi OS (64 bit) beta test version feedback