QCamera#

The QCamera class provides interface for system camera devices. More

Inheritance diagram of PySide6.QtMultimedia.QCamera

Synopsis#

Properties#

Functions#

Slots#

Signals#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

QCamera can be used within a QMediaCaptureSession for video recording and image taking.

You can use QCameraDevice to list available cameras and choose which one to use.

cameras = QMediaDevices.videoInputs()
for cameraDevice in cameras:
    if cameraDevice.description() == "mycamera":
        camera = QCamera(cameraDevice)

On hardware that supports it, QCamera lets you adjust the focus and zoom. This also includes functionality such as a “Macro” mode for close up work (e.g. reading barcodes, or recognizing letters), or “touch to focus” - indicating an interesting area of the image for the hardware to attempt to focus on.

camera.setFocusPointMode(QCamera.FocusModeManual)
camera.setCustomFocusPoint(QPointF(0.25f, 0.75f)) # A point near the bottom left, 25% away from the corner, near that shiny vase

The minimumZoomFactor() and maximumZoomFactor() methods provide the range of supported zoom factors. The zoomTo() method allows changing the zoom factor.

camera.setZoomFactor(3.0)

After capturing the raw data for a camera frame, the camera hardware and software performs various image processing tasks to produce the final image. This includes compensating for ambient light color, reducing noise, as well as making some other adjustments to the image.

You can control many of these processing steps through the Camera properties. For example, you can set the white balance (or color temperature) used for processing images:

camera.setWhiteBalanceMode(QCamera.WhiteBalanceFluorescent)

For more information on image processing of camera frames, see Camera Image Processing .

See the camera overview for more information.

class PySide6.QtMultimedia.QCamera(position[, parent=None])#

PySide6.QtMultimedia.QCamera([parent=None])

PySide6.QtMultimedia.QCamera(cameraDevice[, parent=None])

Parameters:

Construct a 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.

Construct a QCamera with a parent.

Selects the default camera on the system if more than one camera is available.

Construct a QCamera from a camera description cameraDevice and parent.

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property PᅟySide6.QtMultimedia.QCamera.active: bool#

Describes whether the camera is currently active.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.cameraDevice: PySide6.QtMultimedia.QCameraDevice#

Returns the QCameraDevice object associated with this camera.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.cameraFormat: PySide6.QtMultimedia.QCameraFormat#

Returns the camera format currently used by the camera.

Note

When using the FFMPEG backend on an Android target device if you request YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a semi-planar NV12/NV21. This depends on the codec implemented by the device OEM.

See also

videoFormats

Access functions:
property PᅟySide6.QtMultimedia.QCamera.colorTemperature: int#

Returns the current color temperature if the current white balance mode is WhiteBalanceManual. For other modes the return value is undefined.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.customFocusPoint: PySide6.QtCore.QPointF#

This property represents the position of the custom focus point, in relative frame coordinates: QPointF(0,0) points to the left top frame point, QPointF(0.5,0.5) points to the frame center.

The custom focus point property is used only in FocusPointCustom focus mode.

You can check whether custom focus points are supported by querying supportedFeatures() with the Feature. CustomFocusPoint flag.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.error: Error#

Returns the error state of the camera.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.errorString: str#

Returns a human readable string describing a camera’s error state.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.exposureCompensation: float#

This property holds Exposure compensation in EV units..

Exposure compensation property allows to adjust the automatically calculated exposure.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.exposureMode: ExposureMode#

This property holds The exposure mode being used..

Access functions:
property PᅟySide6.QtMultimedia.QCamera.exposureTime: float#

This property holds Camera’s exposure time in seconds..

Access functions:
property PᅟySide6.QtMultimedia.QCamera.flashMode: FlashMode#

This property holds The flash mode being used..

Enables a certain flash mode if the camera has a flash.

See also

FlashMode isFlashModeSupported isFlashReady

Access functions:
property PᅟySide6.QtMultimedia.QCamera.flashReady: bool#

This property holds Indicates if the flash is charged and ready to use..

Access functions:
property PᅟySide6.QtMultimedia.QCamera.focusDistance: float#

This property return an approximate focus distance of the camera. The value reported is between 0 and 1, 0 being the closest possible focus distance, 1 being as far away as possible. Note that 1 is often, but not always infinity.

Setting the focus distance will be ignored unless the focus mode is set to FocusModeManual .

Access functions:
property PᅟySide6.QtMultimedia.QCamera.focusMode: FocusMode#

This property holds the current camera focus mode..

Sets up different focus modes for the camera. All auto focus modes will focus continuously. Locking the focus is possible by setting the focus mode to FocusModeManual . This will keep the current focus and stop any automatic focusing.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.focusPoint: PySide6.QtCore.QPointF#

Returns the point currently used by the auto focus system to focus onto.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.isoSensitivity: int#

This property holds The sensor ISO sensitivity..

Describes the ISO sensitivity currently used by the camera.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.manualExposureTime: int#

Set the manual exposure time to seconds

Access functions:
property PᅟySide6.QtMultimedia.QCamera.manualIsoSensitivity: int#

This property Describes a manually set ISO sensitivity.

Setting this property to -1 (the default), implies that the camera automatically adjusts the ISO sensitivity.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.maximumZoomFactor: float#

Returns the maximum zoom factor.

This will be 1.0 on cameras that do not support zooming.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.minimumZoomFactor: float#

Returns the minimum zoom factor.

This will be 1.0 on cameras that do not support zooming.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.supportedFeatures: Combination of QCamera.Feature#

Returns the features supported by this camera.

See also

Feature

Access functions:
property PᅟySide6.QtMultimedia.QCamera.torchMode: TorchMode#

This property holds The torch mode being used..

A torch is a continuous source of light. It can be used during video recording in low light conditions. Enabling torch mode will usually override any currently set flash mode.

See also

TorchMode isTorchModeSupported flashMode

Access functions:
property PᅟySide6.QtMultimedia.QCamera.whiteBalanceMode: WhiteBalanceMode#

Returns the white balance mode being used.

Access functions:
property PᅟySide6.QtMultimedia.QCamera.zoomFactor: float#

This property holds The current zoom factor..

Gets or sets the current zoom factor. Values will be clamped between minimumZoomFactor and maximumZoomFactor .

Access functions:
PySide6.QtMultimedia.QCamera.Error#

This enum holds the last error code.

Constant

Description

QCamera.NoError

No errors have occurred.

QCamera.CameraError

An error has occurred.

PySide6.QtMultimedia.QCamera.FocusMode#

Constant

Description

QCamera.FocusModeAuto

Continuous auto focus mode.

QCamera.FocusModeAutoNear

Continuous auto focus mode on near objects.

QCamera.FocusModeAutoFar

Continuous auto focus mode on objects far away.

QCamera.FocusModeHyperfocal

Focus to hyperfocal distance, with the maximum depth of field achieved. All objects at distances from half of this distance out to infinity will be acceptably sharp.

QCamera.FocusModeInfinity

Focus strictly to infinity.

QCamera.FocusModeManual

Manual or fixed focus mode.

New in version 6.1.

PySide6.QtMultimedia.QCamera.FlashMode#

Constant

Description

QCamera.FlashOff

Flash is Off.

QCamera.FlashOn

Flash is On.

QCamera.FlashAuto

Automatic flash.

New in version 6.1.

PySide6.QtMultimedia.QCamera.TorchMode#

Constant

Description

QCamera.TorchOff

Torch is Off.

QCamera.TorchOn

Torch is On.

QCamera.TorchAuto

Automatic torch.

New in version 6.1.

PySide6.QtMultimedia.QCamera.ExposureMode#

Constant

Description

QCamera.ExposureAuto

Automatic mode.

QCamera.ExposureManual

Manual mode.

QCamera.ExposurePortrait

Portrait exposure mode.

QCamera.ExposureNight

Night mode.

QCamera.ExposureSports

Spots exposure mode.

QCamera.ExposureSnow

Snow exposure mode.

QCamera.ExposureBeach

Beach exposure mode.

QCamera.ExposureAction

Action mode. Since 5.5

QCamera.ExposureLandscape

Landscape mode. Since 5.5

QCamera.ExposureNightPortrait

Night portrait mode. Since 5.5

QCamera.ExposureTheatre

Theatre mode. Since 5.5

QCamera.ExposureSunset

Sunset mode. Since 5.5

QCamera.ExposureSteadyPhoto

Steady photo mode. Since 5.5

QCamera.ExposureFireworks

Fireworks mode. Since 5.5

QCamera.ExposureParty

Party mode. Since 5.5

QCamera.ExposureCandlelight

Candlelight mode. Since 5.5

QCamera.ExposureBarcode

Barcode mode. Since 5.5

New in version 6.1.

PySide6.QtMultimedia.QCamera.WhiteBalanceMode#

Constant

Description

QCamera.WhiteBalanceAuto

Auto white balance mode.

QCamera.WhiteBalanceManual

Manual white balance. In this mode the white balance should be set with setColorTemperature()

QCamera.WhiteBalanceSunlight

Sunlight white balance mode.

QCamera.WhiteBalanceCloudy

Cloudy white balance mode.

QCamera.WhiteBalanceShade

Shade white balance mode.

QCamera.WhiteBalanceTungsten

Tungsten (incandescent) white balance mode.

QCamera.WhiteBalanceFluorescent

Fluorescent white balance mode.

QCamera.WhiteBalanceFlash

Flash white balance mode.

QCamera.WhiteBalanceSunset

Sunset white balance mode.

New in version 6.1.

PySide6.QtMultimedia.QCamera.Feature#

(inherits enum.Flag) Describes a set of features supported by the camera. The returned value can be a combination of:

Constant

Description

QCamera.Feature.ColorTemperature

The Camera supports setting a custom colorTemperature .

QCamera.Feature.ExposureCompensation

The Camera supports setting a custom exposureCompensation .

QCamera.Feature.IsoSensitivity

The Camera supports setting a custom isoSensitivity .

QCamera.Feature.ManualExposureTime

The Camera supports setting a manual exposure Time .

QCamera.Feature.CustomFocusPoint

The Camera supports setting a custom focus point .

QCamera.Feature.FocusDistance

The Camera supports setting the focusDistance property.

New in version 6.1.

PySide6.QtMultimedia.QCamera.activeChanged(arg__1)#
Parameters:

arg__1 – bool

Notification signal of property active .

PySide6.QtMultimedia.QCamera.brightnessChanged()#
PySide6.QtMultimedia.QCamera.cameraDevice()#
Return type:

PySide6.QtMultimedia.QCameraDevice

Getter of property cameraDevice .

PySide6.QtMultimedia.QCamera.cameraDeviceChanged()#

Notification signal of property cameraDevice .

PySide6.QtMultimedia.QCamera.cameraFormat()#
Return type:

PySide6.QtMultimedia.QCameraFormat

Getter of property cameraFormat .

PySide6.QtMultimedia.QCamera.cameraFormatChanged()#

Notification signal of property cameraFormat .

PySide6.QtMultimedia.QCamera.captureSession()#
Return type:

PySide6.QtMultimedia.QMediaCaptureSession

Returns the capture session this camera is connected to, or a nullptr if the camera is not connected to a capture session.

use setCamera() to connect the camera to a session.

PySide6.QtMultimedia.QCamera.colorTemperature()#
Return type:

int

Getter of property colorTemperature .

PySide6.QtMultimedia.QCamera.colorTemperatureChanged()#

Notification signal of property colorTemperature .

PySide6.QtMultimedia.QCamera.contrastChanged()#
PySide6.QtMultimedia.QCamera.customFocusPoint()#
Return type:

PySide6.QtCore.QPointF

Getter of property customFocusPoint .

PySide6.QtMultimedia.QCamera.customFocusPointChanged()#

Notification signal of property customFocusPoint .

PySide6.QtMultimedia.QCamera.error()#
Return type:

Error

Getter of property error .

PySide6.QtMultimedia.QCamera.errorChanged()#

Notification signal of property error .

PySide6.QtMultimedia.QCamera.errorOccurred(error, errorString)#
Parameters:
  • errorError

  • errorString – str

This signal is emitted when error state changes to error. A description of the error is provided as errorString.

PySide6.QtMultimedia.QCamera.errorString()#
Return type:

str

Getter of property errorString .

PySide6.QtMultimedia.QCamera.exposureCompensation()#
Return type:

float

Getter of property exposureCompensation .

PySide6.QtMultimedia.QCamera.exposureCompensationChanged(arg__1)#
Parameters:

arg__1 – float

Signal emitted when the exposure compensation changes to value.

Notification signal of property exposureCompensation .

PySide6.QtMultimedia.QCamera.exposureMode()#
Return type:

ExposureMode

Getter of property exposureMode .

PySide6.QtMultimedia.QCamera.exposureModeChanged()#

Notification signal of property exposureMode .

PySide6.QtMultimedia.QCamera.exposureTime()#
Return type:

float

Returns the current exposure time in seconds.

Getter of property exposureTime .

PySide6.QtMultimedia.QCamera.exposureTimeChanged(speed)#
Parameters:

speed – float

Signals that a camera’s exposure speed has changed.

Notification signal of property exposureTime .

PySide6.QtMultimedia.QCamera.flashMode()#
Return type:

FlashMode

See also

setFlashMode()

Getter of property flashMode .

PySide6.QtMultimedia.QCamera.flashModeChanged()#

Notification signal of property flashMode .

PySide6.QtMultimedia.QCamera.flashReady(arg__1)#
Parameters:

arg__1 – bool

Signal the flash ready status has changed.

Notification signal of property flashReady .

PySide6.QtMultimedia.QCamera.focusDistance()#
Return type:

float

Getter of property focusDistance .

PySide6.QtMultimedia.QCamera.focusDistanceChanged(arg__1)#
Parameters:

arg__1 – float

Notification signal of property focusDistance .

PySide6.QtMultimedia.QCamera.focusMode()#
Return type:

FocusMode

See also

setFocusMode()

Getter of property focusMode .

PySide6.QtMultimedia.QCamera.focusModeChanged()#

Signals when the focusMode changes.

PySide6.QtMultimedia.QCamera.focusPoint()#
Return type:

PySide6.QtCore.QPointF

Getter of property focusPoint .

PySide6.QtMultimedia.QCamera.focusPointChanged()#

Notification signal of property focusPoint .

PySide6.QtMultimedia.QCamera.hueChanged()#
PySide6.QtMultimedia.QCamera.isActive()#
Return type:

bool

Returns true if the camera is currently active.

Getter of property active .

PySide6.QtMultimedia.QCamera.isAvailable()#
Return type:

bool

Returns true if the camera can be used.

PySide6.QtMultimedia.QCamera.isExposureModeSupported(mode)#
Parameters:

modeExposureMode

Return type:

bool

Returns true if the exposure mode is supported.

PySide6.QtMultimedia.QCamera.isFlashModeSupported(mode)#
Parameters:

modeFlashMode

Return type:

bool

Returns true if the flash mode is supported.

PySide6.QtMultimedia.QCamera.isFlashReady()#
Return type:

bool

Returns true if flash is charged.

Getter of property flashReady .

PySide6.QtMultimedia.QCamera.isFocusModeSupported(mode)#
Parameters:

modeFocusMode

Return type:

bool

Returns true if the focus mode is supported by the camera.

PySide6.QtMultimedia.QCamera.isTorchModeSupported(mode)#
Parameters:

modeTorchMode

Return type:

bool

Returns true if the torch mode is supported.

PySide6.QtMultimedia.QCamera.isWhiteBalanceModeSupported(mode)#
Parameters:

modeWhiteBalanceMode

Return type:

bool

Returns true if the white balance mode is supported.

PySide6.QtMultimedia.QCamera.isoSensitivity()#
Return type:

int

Getter of property isoSensitivity .

PySide6.QtMultimedia.QCamera.isoSensitivityChanged(arg__1)#
Parameters:

arg__1 – int

Signal emitted when sensitivity changes to value.

Notification signal of property isoSensitivity .

PySide6.QtMultimedia.QCamera.manualExposureTime()#
Return type:

float

Returns the manual exposure time in seconds, or -1 if the camera is using automatic exposure times.

PySide6.QtMultimedia.QCamera.manualExposureTimeChanged(speed)#
Parameters:

speed – float

Notification signal of property manualExposureTime .

PySide6.QtMultimedia.QCamera.manualIsoSensitivity()#
Return type:

int

Getter of property manualIsoSensitivity .

PySide6.QtMultimedia.QCamera.manualIsoSensitivityChanged(arg__1)#
Parameters:

arg__1 – int

Notification signal of property manualIsoSensitivity .

PySide6.QtMultimedia.QCamera.maximumExposureTime()#
Return type:

float

The maximal exposure time in seconds.

PySide6.QtMultimedia.QCamera.maximumIsoSensitivity()#
Return type:

int

Returns the maximum ISO sensitivity supported by the camera.

PySide6.QtMultimedia.QCamera.maximumZoomFactor()#
Return type:

float

Getter of property maximumZoomFactor .

PySide6.QtMultimedia.QCamera.maximumZoomFactorChanged(arg__1)#
Parameters:

arg__1 – float

Notification signal of property maximumZoomFactor .

PySide6.QtMultimedia.QCamera.minimumExposureTime()#
Return type:

float

The minimal exposure time in seconds.

PySide6.QtMultimedia.QCamera.minimumIsoSensitivity()#
Return type:

int

Returns the minimum ISO sensitivity supported by the camera.

PySide6.QtMultimedia.QCamera.minimumZoomFactor()#
Return type:

float

Getter of property minimumZoomFactor .

PySide6.QtMultimedia.QCamera.minimumZoomFactorChanged(arg__1)#
Parameters:

arg__1 – float

Notification signal of property minimumZoomFactor .

PySide6.QtMultimedia.QCamera.saturationChanged()#
PySide6.QtMultimedia.QCamera.setActive(active)#
Parameters:

active – bool

Turns the camera on if active is true, or off if it’s false.

See also

isActive()

Setter of property active .

PySide6.QtMultimedia.QCamera.setAutoExposureTime()#

Use automatically calculated exposure time

PySide6.QtMultimedia.QCamera.setAutoIsoSensitivity()#

Turn on auto sensitivity

PySide6.QtMultimedia.QCamera.setCameraDevice(cameraDevice)#
Parameters:

cameraDevicePySide6.QtMultimedia.QCameraDevice

Connects the camera object to the physical camera device described by cameraDevice. Using a default constructed QCameraDevice object as cameraDevice will connect the camera to the system default camera device.

See also

cameraDevice()

Setter of property cameraDevice .

PySide6.QtMultimedia.QCamera.setCameraFormat(format)#
Parameters:

formatPySide6.QtMultimedia.QCameraFormat

Tells the camera to use the format described by format. This can be used to define a specific resolution and frame rate to be used for recording and image capture.

Note

When using the FFMPEG backend on an Android target device if you request YUV420P format, you will receive either a fully planar 4:2:0 YUV420P or a semi-planar NV12/NV21. This depends on the codec implemented by the device OEM.

See also

cameraFormat()

Setter of property cameraFormat .

PySide6.QtMultimedia.QCamera.setColorTemperature(colorTemperature)#
Parameters:

colorTemperature – int

Sets manual white balance to colorTemperature. This is used when whiteBalanceMode() is set to WhiteBalanceManual. The units are Kelvin.

Setting a color temperature will only have an effect if WhiteBalanceManual is supported. In this case, setting a temperature greater 0 will automatically set the white balance mode to WhiteBalanceManual . Setting the temperature to 0 will reset the white balance mode to WhiteBalanceAuto .

Setter of property colorTemperature .

PySide6.QtMultimedia.QCamera.setCustomFocusPoint(point)#
Parameters:

pointPySide6.QtCore.QPointF

Setter of property customFocusPoint .

PySide6.QtMultimedia.QCamera.setExposureCompensation(ev)#
Parameters:

ev – float

Setter of property exposureCompensation .

PySide6.QtMultimedia.QCamera.setExposureMode(mode)#
Parameters:

modeExposureMode

See also

exposureMode()

Setter of property exposureMode .

PySide6.QtMultimedia.QCamera.setFlashMode(mode)#
Parameters:

modeFlashMode

See also

flashMode()

Setter of property flashMode .

PySide6.QtMultimedia.QCamera.setFocusDistance(d)#
Parameters:

d – float

See also

focusDistance()

Setter of property focusDistance .

PySide6.QtMultimedia.QCamera.setFocusMode(mode)#
Parameters:

modeFocusMode

See also

focusMode()

Setter of property focusMode .

PySide6.QtMultimedia.QCamera.setManualExposureTime(seconds)#
Parameters:

seconds – float

PySide6.QtMultimedia.QCamera.setManualIsoSensitivity(iso)#
Parameters:

iso – int

Setter of property manualIsoSensitivity .

PySide6.QtMultimedia.QCamera.setTorchMode(mode)#
Parameters:

modeTorchMode

See also

torchMode()

Setter of property torchMode .

PySide6.QtMultimedia.QCamera.setWhiteBalanceMode(mode)#
Parameters:

modeWhiteBalanceMode

Sets the white balance to mode.

Setter of property whiteBalanceMode .

PySide6.QtMultimedia.QCamera.setZoomFactor(factor)#
Parameters:

factor – float

Zooms to a zoom factor factor at a rate of 1 factor per second.

See also

zoomFactor()

Setter of property zoomFactor .

PySide6.QtMultimedia.QCamera.start()#

Starts the camera.

Same as setActive (true).

If the camera can’t be started for some reason, the errorOccurred() signal is emitted.

PySide6.QtMultimedia.QCamera.stop()#

Stops the camera. Same as setActive (false).

PySide6.QtMultimedia.QCamera.supportedFeatures()#
Return type:

Combination of QCamera.Feature

Getter of property supportedFeatures .

PySide6.QtMultimedia.QCamera.supportedFeaturesChanged()#

Notification signal of property supportedFeatures .

PySide6.QtMultimedia.QCamera.torchMode()#
Return type:

TorchMode

See also

setTorchMode()

Getter of property torchMode .

PySide6.QtMultimedia.QCamera.torchModeChanged()#

Notification signal of property torchMode .

PySide6.QtMultimedia.QCamera.whiteBalanceMode()#
Return type:

WhiteBalanceMode

Getter of property whiteBalanceMode .

PySide6.QtMultimedia.QCamera.whiteBalanceModeChanged()#

Notification signal of property whiteBalanceMode .

PySide6.QtMultimedia.QCamera.zoomFactor()#
Return type:

float

See also

setZoomFactor()

Getter of property zoomFactor .

PySide6.QtMultimedia.QCamera.zoomFactorChanged(arg__1)#
Parameters:

arg__1 – float

Notification signal of property zoomFactor .

PySide6.QtMultimedia.QCamera.zoomTo(zoom, rate)#
Parameters:
  • zoom – float

  • rate – float

Zooms to a zoom factor factor using rate.

The rate is specified in powers of two per second. At a rate of 1 it would take 2 seconds to go from a zoom factor of 1 to 4.

Note

Using a specific rate is not supported on all cameras. If not supported, zooming will happen as fast as possible.