def picamera():
# Picamera will raise an OSError when importing unless the code is run
# on an RPI due to firmware dependencies. Make the imports local so we
# won't have to deal with this nuance when not calling this method.
import picamera
import picamera.array
with picamera.PiCamera() as camera:
camera.resolution = (640, 480)
time.sleep(0.1) # allow the camera time to warm up
with picamera.array.PiRGBArray(camera, size=(640, 480)) as stream:
if camera.closed:
raise CameraInitializationError('Camera failed to open.')
for frame in camera.capture_continuous(stream, format='bgr', use_video_port=True):
image = frame.array
yield image
# Clear the stream in preparation for the next frame
stream.truncate(0)
# TODO documentation
评论列表
文章目录