内容表

上一话题

QAudioRoleControl

下一话题

QCameraCaptureBufferFormatControl

QCamera

QCamera class provides interface for system camera devices. 更多

Inheritance diagram of PySide2.QtMultimedia.QCamera

概要

函数

信号

静态函数

详细描述

QCamera can be used with QCameraViewfinder for viewfinder display, QMediaRecorder for video recording and QCameraImageCapture for image taking.

可以使用 QCameraInfo to list available cameras and choose which one to use.

const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
for (const QCameraInfo &cameraInfo : cameras) {
    if (cameraInfo.deviceName() == "mycamera")
        camera = new QCamera(cameraInfo);
}
											

摄像头概述 了解更多信息。

class QCamera ( position [ , parent=None ] )

QCamera([parent=None])

QCamera(deviceName[, parent=None])

QCamera(cameraInfo[, parent=None])

param parent

QObject

param cameraInfo

QCameraInfo

param deviceName

QByteArray

param position

Position

构造 QCamera which uses a hardware camera located a the specified position .

For example on a mobile phone it can be used to easily choose between front-facing and back-facing cameras.

If no camera is available at the specified position or if position is UnspecifiedPosition , the default camera is used.

构造 QCamera 采用 parent .

PySide2.QtMultimedia.QCamera. Status

This enum holds the current status of the camera.

常量

描述

QCamera.ActiveStatus

The camera has been started and can produce data. The viewfinder displays video frames in active state. Depending on backend, changing some camera settings like capture mode, codecs or resolution in ActiveState may lead to changing the camera status to and while the settings are applied and back to when the camera is ready.

QCamera.StartingStatus

The camera is starting in result of state transition to ActiveState . The camera service is not ready to capture yet.

QCamera.StoppingStatus

The camera is stopping in result of state transition from ActiveState to LoadedState or UnloadedState .

QCamera.StandbyStatus

The camera is in the power saving standby mode. The camera may come to the standby mode after some time of inactivity in the LoadedState 状态。

QCamera.LoadedStatus

The camera is loaded and ready to be configured. This status indicates the camera device is opened and it’s possible to query for supported image and video capture settings, like resolution, framerate and codecs.

QCamera.LoadingStatus

The camera device loading in result of state transition from UnloadedState to LoadedState or ActiveState .

QCamera.UnloadingStatus

The camera device is unloading in result of state transition from LoadedState or ActiveState to UnloadedState .

QCamera.UnloadedStatus

The initial camera status, with camera not loaded. The camera capabilities including supported capture settings may be unknown.

QCamera.UnavailableStatus

The camera or camera backend is not available.

PySide2.QtMultimedia.QCamera. State

This enum holds the current state of the camera.

常量

描述

QCamera.UnloadedState

The initial camera state, with camera not loaded. The camera capabilities, except supported capture modes, are unknown. While the supported settings are unknown in this state, it’s allowed to set the camera capture settings like codec, resolution, or frame rate.

QCamera.LoadedState

The camera is loaded and ready to be configured. In this state it’s allowed to query camera capabilities, set capture resolution, codecs, etc. The viewfinder is not active in the loaded state. The camera consumes power in the loaded state.

QCamera.ActiveState

In the active state as soon as camera is started the viewfinder displays video frames and the camera is ready for capture.

PySide2.QtMultimedia.QCamera. CaptureMode

This enum holds the capture mode of the camera.

常量

描述

QCamera.CaptureViewfinder

Camera is only configured to display viewfinder.

QCamera.CaptureStillImage

Camera is configured for still frames capture.

QCamera.CaptureVideo

Camera is configured for video capture.

PySide2.QtMultimedia.QCamera. Error

This enum holds the last error code.

常量

描述

QCamera.NoError

没有发生错误。

QCamera.CameraError

有发生错误。

QCamera.InvalidRequestError

System resource doesn’t support requested functionality.

QCamera.ServiceMissingError

没有可用摄像头服务。

QCamera.NotSupportedFeatureError

不支持特征。

PySide2.QtMultimedia.QCamera. LockStatus

This enum holds the overall status for all the requested camera locks.

常量

描述

QCamera.Unlocked

The application is not interested in camera settings value. The camera may keep this parameter without changes, this is common with camera focus, or adjust exposure and white balance constantly to keep the viewfinder image nice.

QCamera.Searching

The application has requested the camera focus, exposure or white balance lock with searchAndLock() . This state indicates the camera is focusing or calculating exposure and white balance.

QCamera.Locked

The camera focus, exposure or white balance is locked. The camera is ready to capture, application may check the exposure stays the same, parameters. The Locked status usually means the requested parameter except in the cases when the parameter is requested to be constantly updated. For example, in continuous focusing mode, the focus is considered locked as long as the object is in focus, even while the actual focusing distance may be constantly changing.

PySide2.QtMultimedia.QCamera. LockChangeReason

This enum holds the reason why the camera lock status changed.

常量

描述

QCamera.UserRequest

The lock status changed in result of user request, usually to unlock camera settings.

QCamera.LockAcquired

The lock status successfuly changed to Locked .

QCamera.LockFailed

The camera failed to acquire the requested lock in result of autofocus failure, exposure out of supported range, etc.

QCamera.LockLost

The camera is not able to maintain the requested lock any more. Lock status is changed to Unlocked .

QCamera.LockTemporaryLost

The lock is lost, but the camera is working hard to reacquire it. This value may be used in continuous focusing mode, when the camera loses the focus, the focus lock state is changed to Qcamera::Searching with reason.

PySide2.QtMultimedia.QCamera. LockType

This enum holds the camera lock type.

常量

描述

QCamera.NoLock

QCamera.LockExposure

Lock camera exposure.

QCamera.LockWhiteBalance

Lock the white balance.

QCamera.LockFocus

Lock camera focus.

PySide2.QtMultimedia.QCamera. Position

This enum specifies the physical position of the camera on the system hardware.

常量

描述

QCamera.UnspecifiedPosition

The camera position is unspecified or unknown.

QCamera.BackFace

The camera is on the back face of the system hardware. For example on a mobile device, it means it is on the opposite side to that of the screen.

QCamera.FrontFace

The camera is on the front face of the system hardware. For example on a mobile device, it means it is on the same side as that of the screen. Viewfinder frames of front-facing cameras are mirrored horizontally, so the users can see themselves as looking into a mirror. Captured images or videos are not mirrored.

另请参阅

position()

static PySide2.QtMultimedia.QCamera. availableDevices ( )
返回类型

注意

此函数被弃用。

Returns a list of camera device’s available from the default service provider.

PySide2.QtMultimedia.QCamera. captureMode ( )
返回类型

CaptureModes

另请参阅

setCaptureMode()

PySide2.QtMultimedia.QCamera. captureModeChanged ( arg__1 )
参数

arg__1 CaptureModes

static PySide2.QtMultimedia.QCamera. deviceDescription ( device )
参数

device QByteArray

返回类型

unicode

注意

此函数被弃用。

Returns the description of the device .

PySide2.QtMultimedia.QCamera. error ( )
返回类型

Error

Returns the error state of the object.

PySide2.QtMultimedia.QCamera. error ( arg__1 )
参数

arg__1 Error

PySide2.QtMultimedia.QCamera. errorOccurred ( arg__1 )
参数

arg__1 Error

PySide2.QtMultimedia.QCamera. errorString ( )
返回类型

unicode

Returns a string describing a camera’s error state.

PySide2.QtMultimedia.QCamera. exposure ( )
返回类型

QCameraExposure

Returns the camera exposure control object.

PySide2.QtMultimedia.QCamera. focus ( )
返回类型

QCameraFocus

Returns the camera focus control object.

PySide2.QtMultimedia.QCamera. imageProcessing ( )
返回类型

QCameraImageProcessing

Returns the camera image processing control object.

PySide2.QtMultimedia.QCamera. isCaptureModeSupported ( mode )
参数

mode CaptureModes

返回类型

bool

Returns true if the capture mode is suported.

PySide2.QtMultimedia.QCamera. load ( )

Opens the camera device. The camera state is changed to LoadedState .

It’s not necessary to explicitly load the camera, unless the application needs to read the supported camera settings and change the default values according to the camera capabilities.

In all the other cases, it’s possible to start the camera directly from the unloaded state.

/sa UnloadedState

PySide2.QtMultimedia.QCamera. lockFailed ( )
PySide2.QtMultimedia.QCamera. lockStatus ( )
返回类型

LockStatus

Returns the status of requested camera settings locks.

PySide2.QtMultimedia.QCamera. lockStatus ( lock )
参数

lock LockType

返回类型

LockStatus

Returns the lock status for a given lockType .

PySide2.QtMultimedia.QCamera. lockStatusChanged ( status , reason )
参数
PySide2.QtMultimedia.QCamera. lockStatusChanged ( lock , status , reason )
参数
PySide2.QtMultimedia.QCamera. locked ( )
PySide2.QtMultimedia.QCamera. requestedLocks ( )
返回类型

LockTypes

Returns the requested lock types.

PySide2.QtMultimedia.QCamera. searchAndLock ( )

Lock all the supported camera settings.

PySide2.QtMultimedia.QCamera. searchAndLock ( locks )
参数

locks LockTypes

Locks the camera settings with the requested locks , including focusing in the single autofocus mode, exposure and white balance if the exposure and white balance modes are not manual.

The camera settings are usually locked before taking one or multiple still images, in responce to the shutter button being half pressed.

locked() signal is emitted when camera settings are successfully locked, otherwise lockFailed() is emitted.

QCamera also emits lockStatusChanged ( LockType , LockStatus ) on individual lock status changes and lockStatusChanged ( LockStatus ) signal on composite status changes.

Locking serves two roles: it initializes calculation of automatic parameter (focusing, calculating the correct exposure and white balance) and allows to keep some or all of those parameters during number of shots.

If the camera doesn’t support keeping one of parameters between shots, the related lock state changes to Unlocked .

It’s also acceptable to relock already locked settings, depending on the lock parameter this initiates new focusing, exposure or white balance calculation.

PySide2.QtMultimedia.QCamera. setCaptureMode ( mode )
参数

mode CaptureModes

另请参阅

captureMode()

PySide2.QtMultimedia.QCamera. setViewfinder ( surface )
参数

surface QAbstractVideoSurface

Sets a video surface as the viewfinder of a camera.

If a viewfinder has already been set on the camera the new surface will replace it.

PySide2.QtMultimedia.QCamera. setViewfinderSettings ( settings )
参数

settings QCameraViewfinderSettings

Sets the viewfinder settings .

If some parameters are not specified, or null settings are passed, the camera will choose default values.

If the camera is used to capture videos or images, the viewfinder settings might be ignored if they conflict with the capture settings. You can check the actual viewfinder settings once the camera is in the QCamera::ActiveStatus 状态。

Changing the viewfinder settings while the camera is in the ActiveState state may cause the camera to be restarted.

另请参阅

viewfinderSettings() supportedViewfinderResolutions() supportedViewfinderFrameRateRanges() supportedViewfinderPixelFormats()

PySide2.QtMultimedia.QCamera. start ( )

Starts the camera.

State is changed to ActiveState if camera is started successfully, otherwise errorOccurred() 信号被发射。

While the camera state is changed to ActiveState , starting the camera service can be asynchronous with the actual status reported with status 特性。

PySide2.QtMultimedia.QCamera. state ( )
返回类型

State

PySide2.QtMultimedia.QCamera. stateChanged ( state )
参数

state State

PySide2.QtMultimedia.QCamera. status ( )
返回类型

Status

PySide2.QtMultimedia.QCamera. statusChanged ( status )
参数

status Status

PySide2.QtMultimedia.QCamera. stop ( )

Stops the camera. The camera state is changed from ActiveState to LoadedState .

In this state, the camera still consumes power.

另请参阅

unload() UnloadedState

PySide2.QtMultimedia.QCamera. supportedLocks ( )
返回类型

LockTypes

Returns the lock types that the camera supports.

PySide2.QtMultimedia.QCamera. supportedViewfinderFrameRateRanges ( [ settings=QCameraViewfinderSettings() ] )
参数

settings QCameraViewfinderSettings

返回类型

Returns a list of supported viewfinder frame rate ranges.

This is a convenience function which retrieves unique frame rate ranges from the supported settings.

If non null viewfinder settings are passed, the returned list is reduced to frame rate ranges supported with partial settings applied.

The camera must be loaded before calling this function, otherwise the returned list is empty.

另请参阅

minimumFrameRate() maximumFrameRate() setViewfinderSettings()

PySide2.QtMultimedia.QCamera. supportedViewfinderPixelFormats ( [ settings=QCameraViewfinderSettings() ] )
参数

settings QCameraViewfinderSettings

返回类型

Returns a list of supported viewfinder pixel formats.

This is a convenience function which retrieves unique pixel formats from the supported settings.

If non null viewfinder settings are passed, the returned list is reduced to pixel formats supported with partial settings applied.

The camera must be loaded before calling this function, otherwise the returned list is empty.

另请参阅

pixelFormat() setViewfinderSettings()

PySide2.QtMultimedia.QCamera. supportedViewfinderResolutions ( [ settings=QCameraViewfinderSettings() ] )
参数

settings QCameraViewfinderSettings

返回类型

Returns a list of supported viewfinder resolutions.

This is a convenience function which retrieves unique resolutions from the supported settings.

If non null viewfinder settings are passed, the returned list is reduced to resolutions supported with partial settings applied.

The camera must be loaded before calling this function, otherwise the returned list is empty.

另请参阅

resolution() setViewfinderSettings()

PySide2.QtMultimedia.QCamera. supportedViewfinderSettings ( [ settings=QCameraViewfinderSettings() ] )
参数

settings QCameraViewfinderSettings

返回类型

Returns a list of supported viewfinder settings.

The list is ordered by preference; preferred settings come first.

可选 settings argument can be used to conveniently filter the results. If settings is non null, the returned list is reduced to settings matching the given partial settings .

The status of the camera must be LoadedStatus before calling this function, otherwise the returned list is empty.

另请参阅

setViewfinderSettings() supportedViewfinderResolutions() supportedViewfinderFrameRateRanges() supportedViewfinderPixelFormats()

PySide2.QtMultimedia.QCamera. unload ( )

Closes the camera device and deallocates the related resources. The camera state is changed to UnloadedState .

PySide2.QtMultimedia.QCamera. unlock ( )

Unlock all the requested camera locks.

PySide2.QtMultimedia.QCamera. unlock ( locks )
参数

locks LockTypes

Unlocks the camera settings specified with locks or cancel the current locking if one is active.

PySide2.QtMultimedia.QCamera. viewfinderSettings ( )
返回类型

QCameraViewfinderSettings

Returns the viewfinder settings being used by the camera.

Settings may change when the camera is started, for example if the viewfinder settings are undefined or if unsupported values are set.

If viewfinder settings are not supported by the camera, it always returns a null QCameraViewfinderSettings 对象。

另请参阅

setViewfinderSettings()