返回首页
IoT Hardware

IoT 硬件:Raspberry Pi Camera

配置

Camera

$ sudo raspi-config
  • 3 Interface Options Configure connections to peripherals
  • P1 Camera Enable/disable connection to the Raspberry Pi Camera
  • Yes
reboot

显存

保证显存 >= 128

  • 查看
$ cat /boot/config.txt | grep gpu_mem
gpu_mem=128
  • 修改
$ vim /boot/config.txt

检测 Camera

如果没有检测出来,可以考虑重新插拔试试。

$ vcgencmd get_camera
supported=1 detected=1

验证

拍照 raspistill

  • 打开摄像头,预览2秒后关闭。
raspistill -t 2000
  • 打开摄像头,5秒后拍照(默认),保存为 image.jpg。
raspistill -o image.jpg
  • 打开摄像头,3秒后拍照,保存为 image.png,宽640:高480。
raspistill -t 3000 -o image.png -e png -w 640 -h 480
  • 打开摄像头,30秒内每2秒保存一张照片。
raspistill -t 30000 -tl 2000 -o image%04d.jpg

录像 raspivid

  • 录5秒1080p30视频
raspivid -t 5000 -o video.h264
  • 录5秒1080p30视频,宽640:高480。
raspivid -t 5000 -o video.h264 -w 640 -h 480

开发

拍照

from time import sleep
from picamera import PiCamera

camera = PiCamera()
camera.resolution = (1024, 768)
camera.start_preview()
sleep(2)
camera.capture('image.jpg')

录像

import picamera

camera = picamera.PiCamera()
camera.resolution = (640, 480)
camera.start_recording('video.h264')
camera.wait_recording(10)
camera.stop_recording()

FAQ

  1. 没有打开 Camera。
$ raspistill -t 2000
mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM)
mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1)
mmal: Failed to create camera component
mmal: main: Failed to create camera component
mmal: Camera is not enabled in this build. Try running "sudo raspi-config" and ensure that "camera" has been enabled
  1. Camera 没有安装好或者有质量问题。
$ raspistill -t 2000
mmal: Cannot read camera info, keeping the defaults for OV5647
mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM)
mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1)
mmal: Failed to create camera component
mmal: main: Failed to create camera component
mmal: Camera is not detected. Please check carefully the camera module is installed correctly

参考资料