找回树莓派的 V4L2 摄像头驱动和 raspistill/vid 命令

   日期:2024-01-22     浏览:49    评论:0    
核心提示:在 Raspberry Pi OS 2021-10-30 的版本更新中。之前的摄像头命令 raspistill 被移除,替代方案是 libcamera。

在 Raspberry Pi OS 2021-10-30 的版本更新中。之前的摄像头命令 raspistill 被移除,替代方案是 libcamera。

这导致之前的一些基于 raspistill 命令的教程无法在新系统里奏效。根据官方的说明,64 位版本的 Raspberry Pi OS 只有 libcamera 而没有 raspistill。但 32 位版本的 Raspberry Pi OS 中,V4L2 驱动程序可以通过手动配置来加载。下面我们来介绍配置方法,让你的程序可以继续在新系统上使用 V4L2 驱动,并可以让 raspistill 命令重新工作。

1、修改 /boot/config.txt

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

sudo nano /etc/modules

#在最后面添加
bcm2835-v4l2

保存、重启树莓派之后再运行检测命令。
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

3、编译安装 raspistill/vid 命令
如果你希望继续使用 raspistill 和 raspivid 命令,按照下面的方法来编译安装。

cd ~
sudo apt install cmake
mkdir bin
git clone https://github.com/raspberrypi/userland
cd userland
./buildme
cp build/bin/* ~/bin/

并将 /home/pi/bin 加入 PATH

PATH=$PATH:/home/pi/bin

export PATH

修改完记得执行行下面的命令,让上一步的修改生效

source ./.profile
raspistill 

"raspistill" Camera App (commit bab9bf8790cd)

Runs camera for specific time, and take JPG capture at end if requested

usage: raspistill [options]

Image parameter commands

-q, --quality   : Set jpeg quality <0 to 100>
-r, --raw   : Add raw bayer data to jpeg metadata
-l, --latest    : Link latest complete image to filename 
 
  
-t, --timeout   : Time (in ms) before takes picture and shuts down (if not specified, set to 5s)
-th, --thumb    : Set thumbnail parameters (x:y:quality) or none
-d, --demo  : Run a demo mode (cycle through range of camera options, no capture)
-e, --encoding  : Encoding to use for output file (jpg, bmp, gif, png)
-x, --exif  : EXIF tag to apply to captures (format as 'key=value') or none
-tl, --timelapse    : Timelapse mode. Takes a picture every 
  
   ms. %d == frame number (Try: -o img_%04d.jpg) -fp, --fullpreview : Run the preview using the still capture resolution (may reduce preview fps) -k, --keypress : Wait between captures for a ENTER, X then ENTER to exit -s, --signal : Wait between captures for a SIGUSR1 or SIGUSR2 from another process -g, --gl : Draw preview to texture instead of using video render component -gc, --glcapture : Capture the GL frame-buffer instead of the camera image # vcgencmd 树莓派专有命令用来对硬件做各种检测,如下检查摄像头信息 vcgencmd get_camera # 返回0,说明没有检测到摄像头信息 supported=0 detected=0 树莓派默认将摄像头通信关闭,此时需要开启: # 运行命令行配置 sudo raspi-config 依次选择 "Interfacing Options" -> " Camera",确定后重启树莓派。 
  
 

此时再次执行以下命令,可以得到摄像头信息了!

vcgencmd get_camera
supported=1 detected=1

树莓派自带 raspistill 可以用来进行摄像头拍照功能,如下命令:

raspistill -v -o test.jpg
raspistill -ifx pastel -hf -vf -o test.jpg
 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服