打开摄像头预览:
# -*- coding: utf-8 -*- from time import sleep from picamera import PiCamera def open_preview(): with PiCamera() as camera: camera.resolution = (320, 240) camera.start_preview() sleep(5) if __name__ == '__main__': open_preview()
函数 open_preview()
用于打开摄像头进行预览
首先,获取一个 PiCamera
对象:
with PiCamera() as camera:
可以设置摄像头的分辨率,当前设为宽 320
,高 240
:
camera.resolution = (320, 240)
打开摄像头进行预览:
camera.start_preview()
暂停 5
秒,即预览 5
秒:
sleep(5)
其他操作 -::对摄像头有一些常用的操作,比如设置分辨率,帧率,是否左右翻转,上下翻转:
def open_preview2(): with PiCamera() as camera: camera.resolution = (320, 240) camera.framerate = 24 camera.hflip = True camera.vflip = True camera.start_preview() sleep(5)