基于https://projects.raspberrypi.org/en/projects/getting-started-with-picamera
from picamera import PiCamera
from time import sleep
camera = PiCamera()
camera.start_preview()
sleep(10)
camera.stop_preview()
保存文件并打开,即可将摄像头开启十秒钟。
旋转摄像头:
camera.rotation = 180
,其中角度可为0,90,180,270
还可设置画面透明度:
camera.start_preview(alpha=200)
其中alpha 的值可为0-255 的任何值
camera.capture('/home/pi/Desktop/image.jpg')
照片以image.jpg 的名字保存在Desktop 目录中
照相至少要在sleep(2) 之后进行,以给予传感器时间适应
连续拍照
camera.start_preview()
for i in range(5):
sleep(5)
camera.capture('/home/pi/Desktop/image%s.jpg' % i)
camera.stop_preview()
依次生成image0.jpg,image1.jpg,…,image4.jpg
camera.start_preview()
camera.start_recording('/home/pi/video.h264')
sleep(10)
camera.stop_recording()
camera.stop_preview()
然后通过终端输入omxplayer video.h264
打开视频(视频会以很快的速度播放,因为omxplayer 的快速帧率)
使用annotate_text
camera.start_preview()
camera.annotate_text = "Hello world!"
sleep(5)
camera.capture('/home/pi/Desktop/text.jpg')
camera.stop_preview()
camera.start_preview()
camera.brightness = 70
sleep(5)
camera.capture('/home/pi/Desktop/bright.jpg')
camera.stop_preview()
camera.annotate_text_size = 50
其数值可为6-160
首先要引入颜色的包
from picamera import PiCamera, Color
然后进行配置
camera.annotate_background = Color('blue')
camera.annotate_foreground = Color('yellow')
对camera.image_effect
进行配置
camera.image_effect = 'colorswap'
其参数可以为:
none, negative, solarize, sketch, denoise, emboss(浮雕), oilpaint(油画), hatch, gpen(二值化), pastel, watercolor(绘画), film, blur, saturation, colorswap, washedout(黑白), posterise, colorpoint, colorbalance, cartoon, deinterlace1, 和 deinterlace2
还可通过迭代进行风格自动更换:
for effect in camera.IMAGE_EFFECTS:
camera.image_effect = effect
camera.annotate_text = "Effect: %s" % effect
sleep(5)
对camera.awb_mode
进行配置
camera.awb_mode = 'sunlight'
其参数可以为:
off, auto, sunlight, cloudy, shade, tungsten, fluorescent, incandescent, flash, and horizon
对camera.exposure_mode
进行配置
camera.start_preview()
camera.exposure_mode = 'beach'
sleep(5)
camera.capture('/home/pi/Desktop/beach.jpg')
camera.stop_preview()
其参数可为:
off, auto, night, nightpreview, backlight, spotlight, sports, snow, beach, verylong, fixedfps, antishake, and fireworks
可在camera.EXPOSURE_MODES
中循环迭代各种效果