Camera — Kivy 2.3.0 documentation
Camera¶ 相机
Module: kivy.uix.camera
Added in 1.0.0
The Camera widget is used to capture and display video from a camera. Once the widget is created, the texture inside the widget will be automatically updated. Our CameraBase implementation is used under the hood:
Camera 控件用于从摄像头捕获并显示视频。一旦该控件被创建,控件内部的纹理将自动更新。在内部,我们使用了 CameraBase 的实现:
cam = Camera()
By default, the first camera found on your system is used. To use a different camera, set the index property:
默认情况下,将使用您系统中找到的第一个摄像头。要使用不同的摄像头,请设置索引属性(index property):
cam = Camera(index=1)
You can also select the camera resolution: 您还可以选择摄像头的分辨率:
resolution 美/ˌrezəˈluːʃ(ə)n/ (电视、照相机、显微镜等的)清晰度,分辨率;
cam = Camera(resolution=(320, 240))
Warning
The camera texture is not updated as soon as you have created the object. The camera initialization is asynchronous, so there may be a delay before the requested texture is created.
在创建对象之后,摄像头的纹理并不会立即更新。摄像头的初始化是异步的,因此在请求的纹理被创建之前可能会有延迟。
APIHide Description ⇑
class kivy.uix.camera.Camera(**kwargs)¶
Bases: kivy.uix.image.Image
Camera class. See module documentation for more information.
index¶
Index of the used camera, starting from 0. 使用的相机的索引,从0开始
index is a NumericProperty and defaults to -1 to allow auto selection.
play¶ 播放
Boolean indicating whether the camera is playing or not. You can start/stop the camera by setting this property:
布尔值,指示摄像头是否正在播放。您可以通过设置此属性来启动/停止摄像头:
# start the camera playing at creation cam = Camera(play=True) # create the camera, and start later (default) cam = Camera(play=False) # and later cam.play = True
play is a BooleanProperty and defaults to False. play是一个波尔值属性 并且默认是 False
resolution¶ 分辨率
Preferred resolution to use when invoking the camera. If you are using [-1, -1], the resolution will be the default one:
当你调用相机时,建议使用的首选分辨率。如果你使用的是[-1, -1]
,那么分辨率将会是默认的:
# create a camera object with the best image available cam = Camera() # create a camera object with an image of 320x240 if possible cam = Camera(resolution=(320, 240))
Warning
Depending on the implementation, the camera may not respect this property.
resolution is a ListProperty and defaults to [-1, -1].