开启摄像头 10秒
# -*- coding: utf-8 -*-
import time
import picamera
camera = picamera.PiCamera()
try:
camera.start_preview()
time.sleep(10)
camera.stop_preview()
finally:
camera.close()
调节亮度
# -*- coding: utf-8 -*-
import time
import picamera
with picamera.PiCamera() as camera:
camera.start_preview()
try:
for i in range(100):
camera.brightness = i
time.sleep(0.2)
finally:
camera.stop_preview()
录像_ 一段可控制大小的视频
# -*- coding: utf-8 -*-
import picamera
with picamera.PiCamera() as camera:
camera.resolution = (640, 480) #视频尺寸 default resolution is 1280x720
camera.start_preview()
camera.start_recording('foo.h264') #文件名字
camera.wait_recording(20) #文件大小
camera.stop_recording()
camera.stop_preview()
截图??
# -*- coding: utf-8 -*-
import time
import picamera
with picamera.PiCamera() as camera:
camera.resolution = (1280, 720)
camera.start_preview()
camera.exposure_compensation = 2
camera.exposure_mode = 'spotlight'
camera.meter_mode = 'matrix'
camera.image_effect = 'gpen'
# Give the camera some time to adjust to conditions
time.sleep(2)
camera.capture('foo.jpg')
camera.stop_preview()
截图 添加tags
# -*- coding: utf-8 -*-
import time
import picamera
with picamera.PiCamera() as camera:
camera.resolution = (2592, 1944) #照片尺寸
camera.start_preview()
time.sleep(2)
camera.exif_tags['IFD0.Artist'] = 'Me!' #作者
camera.exif_tags['IFD0.Copyright'] = 'Copyright (c) 2013 Me!' #版权
camera.capture('foo.jpg')
camera.stop_preview()
延时照片
# -*- coding: utf-8 -*-
import time
import picamera
with picamera.PiCamera() as camera:
camera.resolution = (1280, 720)
camera.start_preview()
time.sleep(1)
for i, filename in enumerate(camera.capture_continuous('image{counter:02d}.jpg')):
#capture_continuous()
#http://picamera.readthedocs.org/en/release-1.9/api.html#picamera.PiCamera.capture_continuous
print('Captured image %s' % filename)
if i == 5: #(0~i)张
break
time.sleep(2) # per 2seconds
camera.stop_preview()
使用video-port 进行capture
# -*- coding: utf-8 -*-
import time
import picamera
with picamera.PiCamera() as camera:
camera.resolution = (640, 480)
camera.start_preview()
start = time.time()
camera.capture_sequence((
#capture_sequence()
#http://picamera.readthedocs.org/en/release-1.9/api.html#picamera.PiCamera.capture_sequence
'image%03d.jpg' % i # %03d--%i
for i in range(120)
), use_video_port=True)
print('Captured 120 images at %.2ffps' % (120 / (time.time() - start)))
camera.stop_preview()
暂时还没搞明白是什么 numpy array
# -*- coding: utf-8 -*-
#This example demonstrates capturing an unencoded image in RGB format and producing a numpy array from the image:
import time
import picamera
import picamera.array
with picamera.PiCamera() as camera:
with picamera.array.PiRGBArray(camera) as stream:
camera.resolution = (1024, 768)
camera.start_preview()
time.sleep(2)
camera.capture(stream, 'rgb')
print(stream.array.shape)
###TOP