class QCamera

The QCamera class provides interface for system camera devices. More

Inheritance diagram of PySide6.QtMultimedia.QCamera

Synopsis

Properties

Methods

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 Error

This enum holds the last error code.

Constant

Description

QCamera.NoError

No errors have occurred.

QCamera.CameraError

An error has occurred.

class 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.

Added in version 6.1.

class FlashMode

Constant

Description

QCamera.FlashOff

Flash is Off.

QCamera.FlashOn

Flash is On.

QCamera.FlashAuto

Automatic flash.

Added in version 6.1.

class TorchMode

Constant

Description

QCamera.TorchOff

Torch is Off.

QCamera.TorchOn

Torch is On.

QCamera.TorchAuto

Automatic torch.

Added in version 6.1.

class 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

Added in version 6.1.

class 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.

Added in version 6.1.

class 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.

Added in version 6.1.

Note

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

property activeᅟ: bool

Describes whether the camera is currently active.

Access functions:
property cameraDeviceᅟ: QCameraDevice

Returns the QCameraDevice object associated with this camera.

Access functions:
property cameraFormatᅟ: 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 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 customFocusPointᅟ: 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 errorᅟ: QCamera.Error

Returns the error state of the camera.

Access functions:
property errorStringᅟ: str

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

Access functions:
property exposureCompensationᅟ: float

This property holds Exposure compensation in EV units..

Exposure compensation property allows to adjust the automatically calculated exposure.

Access functions:
property exposureModeᅟ: QCamera.ExposureMode

This property holds The exposure mode being used..

Access functions:
property exposureTimeᅟ: float

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

Access functions:
property flashModeᅟ: QCamera.FlashMode

This property holds The flash mode being used..

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

Access functions:
property flashReadyᅟ: bool

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

Access functions:
property 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 focusModeᅟ: QCamera.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 focusPointᅟ: QPointF

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

Access functions:
property isoSensitivityᅟ: int

This property holds The sensor ISO sensitivity..

Describes the ISO sensitivity currently used by the camera.

Access functions:
property manualExposureTimeᅟ: int

Set the manual exposure time to seconds

Access functions:
property 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 maximumZoomFactorᅟ: float

Returns the maximum zoom factor.

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

Access functions:
property minimumZoomFactorᅟ: float

Returns the minimum zoom factor.

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

Access functions:
property supportedFeaturesᅟ: Combination of QCamera.Feature

Returns the features supported by this camera.

See also

Feature

Access functions:
property torchModeᅟ: QCamera.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.

Access functions:
property whiteBalanceModeᅟ: QCamera.WhiteBalanceMode

Returns the white balance mode being used.

Access functions:
property 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:
__init__([parent=None])
Parameters:

parentQObject

Construct a QCamera with a parent.

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

__init__(position[, 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.

__init__(cameraDevice[, parent=None])
Parameters:

Construct a QCamera from a camera description cameraDevice and parent.

activeChanged(arg__1)
Parameters:

arg__1 – bool

Notification signal of property activeᅟ .

brightnessChanged()
cameraDevice()
Return type:

QCameraDevice

Getter of property cameraDeviceᅟ .

cameraDeviceChanged()

Notification signal of property cameraDeviceᅟ .

cameraFormat()
Return type:

QCameraFormat

Getter of property cameraFormatᅟ .

cameraFormatChanged()

Notification signal of property cameraFormatᅟ .

captureSession()
Return type:

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.

colorTemperature()
Return type:

int

Getter of property colorTemperatureᅟ .

colorTemperatureChanged()

Notification signal of property colorTemperatureᅟ .

contrastChanged()
customFocusPoint()
Return type:

QPointF

Getter of property customFocusPointᅟ .

customFocusPointChanged()

Notification signal of property customFocusPointᅟ .

error()
Return type:

Error

Getter of property errorᅟ .

errorChanged()

Notification signal of property errorᅟ .

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.

errorString()
Return type:

str

Getter of property errorStringᅟ .

exposureCompensation()
Return type:

float

Getter of property exposureCompensationᅟ .

exposureCompensationChanged(arg__1)
Parameters:

arg__1 – float

Signal emitted when the exposure compensation changes to value.

Notification signal of property exposureCompensationᅟ .

exposureMode()
Return type:

ExposureMode

Getter of property exposureModeᅟ .

exposureModeChanged()

Notification signal of property exposureModeᅟ .

exposureTime()
Return type:

float

Returns the current exposure time in seconds.

Getter of property exposureTimeᅟ .

exposureTimeChanged(speed)
Parameters:

speed – float

Signals that a camera’s exposure speed has changed.

Notification signal of property exposureTimeᅟ .

flashMode()
Return type:

FlashMode

See also

setFlashMode()

Getter of property flashModeᅟ .

flashModeChanged()

Notification signal of property flashModeᅟ .

flashReady(arg__1)
Parameters:

arg__1 – bool

Signal the flash ready status has changed.

Notification signal of property flashReadyᅟ .

focusDistance()
Return type:

float

Getter of property focusDistanceᅟ .

focusDistanceChanged(arg__1)
Parameters:

arg__1 – float

Notification signal of property focusDistanceᅟ .

focusMode()
Return type:

FocusMode

See also

setFocusMode()

Getter of property focusModeᅟ .

focusModeChanged()

Signals when the focusMode changes.

Notification signal of property focusModeᅟ .

focusPoint()
Return type:

QPointF

Getter of property focusPointᅟ .

focusPointChanged()

Notification signal of property focusPointᅟ .

hueChanged()
isActive()
Return type:

bool

Returns true if the camera is currently active.

Getter of property activeᅟ .

isAvailable()
Return type:

bool

Returns true if the camera can be used.

isExposureModeSupported(mode)
Parameters:

modeExposureMode

Return type:

bool

Returns true if the exposure mode is supported.

isFlashModeSupported(mode)
Parameters:

modeFlashMode

Return type:

bool

Returns true if the flash mode is supported.

isFlashReady()
Return type:

bool

Returns true if flash is charged.

Getter of property flashReadyᅟ .

isFocusModeSupported(mode)
Parameters:

modeFocusMode

Return type:

bool

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

isTorchModeSupported(mode)
Parameters:

modeTorchMode

Return type:

bool

Returns true if the torch mode is supported.

isWhiteBalanceModeSupported(mode)
Parameters:

modeWhiteBalanceMode

Return type:

bool

Returns true if the white balance mode is supported.

isoSensitivity()
Return type:

int

Getter of property isoSensitivityᅟ .

isoSensitivityChanged(arg__1)
Parameters:

arg__1 – int

Signal emitted when sensitivity changes to value.

Notification signal of property isoSensitivityᅟ .

manualExposureTime()
Return type:

float

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

manualExposureTimeChanged(speed)
Parameters:

speed – float

Notification signal of property manualExposureTimeᅟ .

manualIsoSensitivity()
Return type:

int

Getter of property manualIsoSensitivityᅟ .

manualIsoSensitivityChanged(arg__1)
Parameters:

arg__1 – int

Notification signal of property manualIsoSensitivityᅟ .

maximumExposureTime()
Return type:

float

The maximal exposure time in seconds.

maximumIsoSensitivity()
Return type:

int

Returns the maximum ISO sensitivity supported by the camera.

maximumZoomFactor()
Return type:

float

Getter of property maximumZoomFactorᅟ .

maximumZoomFactorChanged(arg__1)
Parameters:

arg__1 – float

Notification signal of property maximumZoomFactorᅟ .

minimumExposureTime()
Return type:

float

The minimal exposure time in seconds.

minimumIsoSensitivity()
Return type:

int

Returns the minimum ISO sensitivity supported by the camera.

minimumZoomFactor()
Return type:

float

Getter of property minimumZoomFactorᅟ .

minimumZoomFactorChanged(arg__1)
Parameters:

arg__1 – float

Notification signal of property minimumZoomFactorᅟ .

saturationChanged()
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ᅟ .

setAutoExposureTime()

Use automatically calculated exposure time

setAutoIsoSensitivity()

Turn on auto sensitivity

setCameraDevice(cameraDevice)
Parameters:

cameraDeviceQCameraDevice

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ᅟ .

setCameraFormat(format)
Parameters:

formatQCameraFormat

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ᅟ .

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ᅟ .

setCustomFocusPoint(point)
Parameters:

pointQPointF

Setter of property customFocusPointᅟ .

setExposureCompensation(ev)
Parameters:

ev – float

Setter of property exposureCompensationᅟ .

setExposureMode(mode)
Parameters:

modeExposureMode

See also

exposureMode()

Setter of property exposureModeᅟ .

setFlashMode(mode)
Parameters:

modeFlashMode

See also

flashMode()

Setter of property flashModeᅟ .

setFocusDistance(d)
Parameters:

d – float

See also

focusDistance()

Setter of property focusDistanceᅟ .

setFocusMode(mode)
Parameters:

modeFocusMode

See also

focusMode()

Setter of property focusModeᅟ .

setManualExposureTime(seconds)
Parameters:

seconds – float

setManualIsoSensitivity(iso)
Parameters:

iso – int

Setter of property manualIsoSensitivityᅟ .

setTorchMode(mode)
Parameters:

modeTorchMode

See also

torchMode()

Setter of property torchModeᅟ .

setWhiteBalanceMode(mode)
Parameters:

modeWhiteBalanceMode

Sets the white balance to mode.

Setter of property whiteBalanceModeᅟ .

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ᅟ .

start()

Starts the camera.

Same as setActive (true).

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

stop()

Stops the camera. Same as setActive (false).

supportedFeatures()
Return type:

Combination of Feature

Getter of property supportedFeaturesᅟ .

supportedFeaturesChanged()

Notification signal of property supportedFeaturesᅟ .

torchMode()
Return type:

TorchMode

See also

setTorchMode()

Getter of property torchModeᅟ .

torchModeChanged()

Notification signal of property torchModeᅟ .

whiteBalanceMode()
Return type:

WhiteBalanceMode

Getter of property whiteBalanceModeᅟ .

whiteBalanceModeChanged()

Notification signal of property whiteBalanceModeᅟ .

zoomFactor()
Return type:

float

See also

setZoomFactor()

Getter of property zoomFactorᅟ .

zoomFactorChanged(arg__1)
Parameters:

arg__1 – float

Notification signal of property zoomFactorᅟ .

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.