深度优先

这个家伙好懒,除了文章什么都没留下

0%

【树莓派】CSI摄像头使用指南

摄像头安装

硬件安装

静电处理,切记断电安装,不然摄像头很容易GG

摄像头电路板与 Raspberry Pi 通过一条 15 芯的排线进行连接。

拉起连接座两端的卡扣。

蓝色标记应该正对着网络接口方向。

软件安装

修改树莓派配置,开启摄像头模块。

1
sudo raspi-config

摄像头模块检测

1
2
3
4
5
vcgencmd get_camera
supported=1 detected=1
# 或者
ls -al /dev/video0
crw-rw----+ 1 root video 81, 3 Mar 9 01:06 /dev/video0

摄像头常规操作

目前提供了三个应用程序:

  • raspistill 捕捉图像
  • raspivid 捕捉视频
  • raspistillyuv 捕捉图像

raspistill 使用了图像编码组件,raspivid使用了视频编码组件,raspistillyuv没有使用编码组件,而是直接将 YUV 或 RGB 从摄像组件输出到文件

  • 拍照测试 将显示来自摄像头 5 秒钟的预览图像,并且拍摄一张照片

    1
    raspistill -v -o test.jpg
  • 查看图片

    1
    xdg-open test.jpg
  • 视频录制

    1
    raspivid -o vv.h264 -t 10000s
  • 播放视频

    1
    vlc vv.h264
  • 帮助文档 使用箭头键来滚动,然后键入q退出

    1
    2
    raspivid | less
    raspistill | less
  • 两秒钟(时间单位为毫秒)延迟后拍摄一张照片,并保存为 image.jpg

    1
    raspistill -t 2000 -o image.jpg
  • 拍摄一张自定义大小的照片

    1
    raspistill -t 2000 -o image.jpg -w 640 -h 480
  • 降低图像质量,减小文件尺寸

    1
    raspistill -t 2000 -o image.jpg -q 5
  • 强制使预览窗口出现在坐标为 100,100 的位置,并且尺寸为宽 300 和高 200 像素

    1
    raspistill -t 2000 -o image.jpg -p 100,100,300,200
  • 禁用预览窗口

    1
    raspistill -t 2000 -o image.jpg
  • 将图像保存为 PNG 文件(无损压缩格式,但是要比 JPEG 速度慢)。注意,当选择图像编码时,文件扩展名将被忽略

    1
    raspistill -t 2000 -o image.png –e png
  • 向 JPEG 文件中添加一些 EXIF 信息。该命令将会把作者名称标签设置为 Dreamcolor,GPS 海拔高度为 123.5米

    1
    raspistill -t 2000 -o image.jpg -x IFD0.Artist=Dreamcolor -x GPS.GPSAltitude=1235/10
  • 设置浮雕风格图像特效

    1
    raspistill -t 2000 -o image.jpg -ifx emboss
  • 设置 YUV 图像的 U 和 V 通道为指定的值(128:128 为黑白图像)

    1
    raspistill -t 2000 -o image.jpg -cfx 128:128
  • 仅显示两秒钟预览图像,而不对图像进行保存

    1
    raspistill -t 2000
  • 间隔获取图片,在 10 分钟(10 分钟 = 600000 毫秒)的时间里,每 10 秒获取一张,并且命名为 image_number_001_today.jpg,image_number_002_today.jpg… 的形式,并且最后一张照片将命名为 latest.jpg。

    1
    raspistill -t 600000 -tl 10000 -o image_num_%03d_today.jpg -l latest.jpg
  • 获取一张照片并发送至标准输出设备

    1
    raspistill -t 2000 -o -
  • 获取一张照片并保存为一个文件

    1
    raspistill -t 2000 -o - > my_file.jpg
  • 摄像头一直工作,当按下回车键时获取一张照片

    1
    raspistill -t 0 -k -o my_pics%02d.jpg
  • 使用默认设置录制一段 5 秒钟的视频片段(1080p30)

    1
    raspivid -t 5000 -o video.h264
  • 使用指定码率(3.5Mbits/s)录制一段 5 秒钟的视频片段

    1
    raspivid -t 5000 -o video.h264 -b 3500000
  • 使用指定帧率(5fps)录制一段 5 秒钟的视频片段

    1
    raspivid -t 5000 -o video.h264 -f 5
  • 发送到标准输出设备一段 5 秒钟经过编码的摄像头流图像

    1
    raspivid -t 5000 -o -
  • 保存到文件一段 5 秒钟经过编码的摄像头流图像

    1
    raspivid -t 5000 -o - > my_file.h264