树莓派摄像头使用常用命令及代码

检测树莓派摄像头是否可用

raspistill -o image.jpg
2592*1944分辨率

直接在终端输入 raspistill 即可查看所有 raspistill的命令选项

间隔一定时间拍摄一张照片
raspistill -t 30000 -tl 2000 -o image%04d.jpg

拍摄一段长度为6000ms的视频并保存为video.h264
raspivid -o video.h264 -t 6000

播放保存下来的视频
omxplpayer video.h264
 

from picamera import PiCamera
import time

camera = PiCamera()
#左右上下翻转
camera.vflip = True
camera.hflip = True
#控制分辨率
#照片最大分辨率2592*1944
#视频最大分辨率1920*1080
#最小分辨率64*64
camera.resolution = (1280,720)
#控制亮度,默认亮度是50,范围是0-100
camera.brightness = 70
camera.framerate = 15

for i in range(100):
    camera.annotate_text ="Contrast: %s"%i
    camera.contrast = i
    time.sleep(0.1)
#摄像头特效
camera.image_effect = 'cartoon'
#查看所有特效
for effect in camera.IMAGE_EFFECTS:
    camera.image_effect = effect
    camera.annotate_text="Effect:%s"% effect
    time.sleep(2)

#保存照片
camera.capture('cam_cap.jpg')
camera.rotation = 180
for i in range(5):
    time.sleep(1)
    camera.capture('cam_cap%s.jpg'%i)

#保存视频
camera.start_recording('video.h264')
time.sleep(10)
camera.stop_recording()



camera.start_preview()
time.sleep(10)
camera.stop_preview()

#精简代码 自动配置资源访问语句
with picamera.PiCamera(0 as camera:
    camera.start_recording('video.h264')
    camera.wait_recording(120)
    camera.stop_recording()
with open(text.txt") as file:
    text_data = file.read()

 

你可能感兴趣的:(树莓派)