IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QCamera Class

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QCamera Class

  • Header: QCamera

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Multimedia)

    target_link_libraries(mytarget PRIVATE Qt6::Multimedia)

  • qmake: QT += multimedia

  • Inherited By:

  • Instantiated By: qml-qtmultimedia-camera.xml

  • Inherits: QObject

  • Group: QCamera is part of multimedia, multimedia_camera

Detailed Description

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.

 
Sélectionnez
const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
for (const QCameraDevice &cameraDevice : cameras) {
    if (cameraDevice.description() == "mycamera")
        camera = new 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.

 
Sélectionnez
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.

 
Sélectionnez
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:

 
Sélectionnez
camera->setWhiteBalanceMode(QCamera::WhiteBalanceFluorescent);

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

See the camera overview for more information.

Member Type Documentation

 

enum QCamera::Error

This enum holds the last error code.

Constant

Value

Description

QCamera::NoError

0

No errors have occurred.

QCamera::CameraError

1

An error has occurred.

enum QCamera::ExposureMode

Constant

Value

Description

QCamera::ExposureAuto

0

Automatic mode.

QCamera::ExposureManual

1

Manual mode.

QCamera::ExposurePortrait

2

Portrait exposure mode.

QCamera::ExposureNight

3

Night mode.

QCamera::ExposureSports

4

Spots exposure mode.

QCamera::ExposureSnow

5

Snow exposure mode.

QCamera::ExposureBeach

6

Beach exposure mode.

QCamera::ExposureAction

7

Action mode. Since 5.5

QCamera::ExposureLandscape

8

Landscape mode. Since 5.5

QCamera::ExposureNightPortrait

9

Night portrait mode. Since 5.5

QCamera::ExposureTheatre

10

Theatre mode. Since 5.5

QCamera::ExposureSunset

11

Sunset mode. Since 5.5

QCamera::ExposureSteadyPhoto

12

Steady photo mode. Since 5.5

QCamera::ExposureFireworks

13

Fireworks mode. Since 5.5

QCamera::ExposureParty

14

Party mode. Since 5.5

QCamera::ExposureCandlelight

15

Candlelight mode. Since 5.5

QCamera::ExposureBarcode

16

Barcode mode. Since 5.5

enum QCamera::Feature

flags QCamera::Features

Describes a set of features supported by the camera. The returned value can be a combination of:

Constant

Value

Description

QCamera::Feature::ColorTemperature

0x1

The Camera supports setting a custom colorTemperature.

QCamera::Feature::ExposureCompensation

0x2

The Camera supports setting a custom exposureCompensation.

QCamera::Feature::IsoSensitivity

0x4

The Camera supports setting a custom isoSensitivity.

QCamera::Feature::ManualExposureTime

0x8

The Camera supports setting a manual exposure Time.

QCamera::Feature::CustomFocusPoint

0x10

The Camera supports setting a custom focus point.

QCamera::Feature::FocusDistance

0x20

The Camera supports setting the focusDistance property.

The Features type is a typedef for QFlags<Feature>. It stores an OR combination of Feature values.

enum QCamera::FlashMode

Constant

Value

Description

QCamera::FlashOff

0

Flash is Off.

QCamera::FlashOn

1

Flash is On.

QCamera::FlashAuto

2

Automatic flash.

enum QCamera::FocusMode

Constant

Value

Description

QCamera::FocusModeAuto

0

Continuous auto focus mode.

QCamera::FocusModeAutoNear

1

Continuous auto focus mode on near objects.

QCamera::FocusModeAutoFar

2

Continuous auto focus mode on objects far away.

QCamera::FocusModeHyperfocal

3

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

4

Focus strictly to infinity.

QCamera::FocusModeManual

5

Manual or fixed focus mode.

enum QCamera::TorchMode

Constant

Value

Description

QCamera::TorchOff

0

Torch is Off.

QCamera::TorchOn

1

Torch is On.

QCamera::TorchAuto

2

Automatic torch.

enum QCamera::WhiteBalanceMode

Constant

Value

Description

QCamera::WhiteBalanceAuto

0

Auto white balance mode.

QCamera::WhiteBalanceManual

1

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

QCamera::WhiteBalanceSunlight

2

Sunlight white balance mode.

QCamera::WhiteBalanceCloudy

3

Cloudy white balance mode.

QCamera::WhiteBalanceShade

4

Shade white balance mode.

QCamera::WhiteBalanceTungsten

5

Tungsten (incandescent) white balance mode.

QCamera::WhiteBalanceFluorescent

6

Fluorescent white balance mode.

QCamera::WhiteBalanceFlash

7

Flash white balance mode.

QCamera::WhiteBalanceSunset

8

Sunset white balance mode.

Property Documentation

 

active : bool

Describes whether the camera is currently active.

Access functions:

Notifier signal:

  • void activeChanged(bool)

cameraDevice : QCameraDevice

Returns the QCameraDevice object associated with this camera.

Access functions:

Notifier signal:

  • void cameraDeviceChanged()

cameraFormat : QCameraFormat

Returns the camera format currently used by the camera.

Access functions:

Notifier signal:

  • void cameraFormatChanged()

See Also

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:

Notifier signal:

  • void colorTemperatureChanged() const

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:

  • customFocusPoint() const

  • void setCustomFocusPoint(const &point)

Notifier signal:

  • void customFocusPointChanged()

[read-only] error : const Error

Returns the error state of the camera.

Access functions:

  • error() const

Notifier signal:

[read-only] errorString : const QString

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

Access functions:

  • errorString() const

Notifier signal:

exposureCompensation : float

Exposure compensation in EV units.

Exposure compensation property allows to adjust the automatically calculated exposure.

Access functions:

  • float exposureCompensation() const

  • void setExposureCompensation(float ev)

Notifier signal:

exposureMode : QCamera::ExposureMode

This property holds the exposure mode being used.

Access functions:

  • exposureMode() const

  • void setExposureMode( mode)

Notifier signal:

  • void exposureModeChanged()

See Also

[read-only] exposureTime : const float

Camera's exposure time in seconds.

Access functions:

Notifier signal:

See Also

flashMode : QCamera::FlashMode

This property holds the flash mode being used.

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

Access functions:

  • flashMode() const

  • void setFlashMode( mode)

Notifier signal:

  • void flashModeChanged()

See Also

[read-only] flashReady : const bool

Indicates if the flash is charged and ready to use.

Access functions:

Notifier signal:

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:

  • float focusDistance() const

  • void setFocusDistance(float d)

Notifier signal:

  • void focusDistanceChanged(float)

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:

  • focusMode() const

  • void setFocusMode( mode)

See Also

[read-only] focusPoint : const QPointF

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

Access functions:

  • focusPoint() const

Notifier signal:

  • void focusPointChanged()

[read-only] isoSensitivity : const int

This property holds the sensor ISO sensitivity.

Describes the ISO sensitivity currently used by the camera.

Access functions:

  • int isoSensitivity() const

Notifier signal:

See Also

manualExposureTime : int

Set the manual exposure time to seconds

Access functions:

Notifier signal:

  • void manualExposureTimeChanged(float speed)

manualIsoSensitivity : int

Describes a manually set ISO sensitivity

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

Access functions:

  • int manualIsoSensitivity() const

  • void setManualIsoSensitivity(int iso)

Notifier signal:

  • void manualIsoSensitivityChanged(int)

[read-only] maximumZoomFactor : const float

Returns the maximum zoom factor.

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

Access functions:

  • float maximumZoomFactor() const

Notifier signal:

  • void maximumZoomFactorChanged(float)

[read-only] minimumZoomFactor : const float

Returns the minimum zoom factor.

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

Access functions:

  • float minimumZoomFactor() const

Notifier signal:

  • void minimumZoomFactorChanged(float)

[read-only] supportedFeatures : const Features

Returns the features supported by this camera.

Access functions:

  • supportedFeatures() const

Notifier signal:

  • void supportedFeaturesChanged()

See Also

See also QCamera::Feature

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:

  • torchMode() const

  • void setTorchMode( mode)

Notifier signal:

  • void torchModeChanged()

See Also

whiteBalanceMode : WhiteBalanceMode

Returns the white balance mode being used.

Access functions:

Notifier signal:

  • void whiteBalanceModeChanged() const

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:

Notifier signal:

  • void zoomFactorChanged(float)

Member Function Documentation

 

[explicit] QCamera::QCamera(QObject *parent = nullptr)

Construct a QCamera with a parent.

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

[explicit] QCamera::QCamera(const QCameraDevice &cameraDevice, QObject *parent = nullptr)

Construct a QCamera from a camera description cameraDevice and parent.

[explicit] QCamera::QCamera(QCameraDevice::Position position, QObject *parent = nullptr)

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 QCameraDevice::UnspecifiedPosition, the default camera is used.

[virtual] QCamera::~QCamera()

Destroys the camera object.

QMediaCaptureSession *QCamera::captureSession() const

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

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

void QCamera::errorOccurred(QCamera::Error error, const QString &errorString)

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

void QCamera::exposureCompensationChanged(float value)

Signal emitted when the exposure compensation changes to value.

Notifier signal for property exposureCompensation.

float QCamera::exposureTime() const

Returns the current exposure time in seconds.

Getter function for property exposureTime.

void QCamera::exposureTimeChanged(float speed)

Signals that a camera's exposure speed has changed.

Notifier signal for property exposureTime.

void QCamera::flashReady(bool ready)

Signal the flash ready status has changed.

Notifier signal for property flashReady.

void QCamera::focusModeChanged()

Signals when the focusMode changes.

bool QCamera::isActive() const

Returns true if the camera is currently active.

Getter function for property active.

bool QCamera::isAvailable() const

Returns true if the camera can be used.

bool QCamera::isExposureModeSupported(QCamera::ExposureMode mode) const

Returns true if the exposure mode is supported.

bool QCamera::isFlashModeSupported(QCamera::FlashMode mode) const

Returns true if the flash mode is supported.

bool QCamera::isFlashReady() const

Returns true if flash is charged.

Getter function for property flashReady.

bool QCamera::isFocusModeSupported(QCamera::FocusMode mode) const

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

bool QCamera::isTorchModeSupported(QCamera::TorchMode mode) const

Returns true if the torch mode is supported.

bool QCamera::isWhiteBalanceModeSupported(QCamera::WhiteBalanceMode mode) const

Returns true if the white balance mode is supported.

void QCamera::isoSensitivityChanged(int value)

Signal emitted when sensitivity changes to value.

Notifier signal for property isoSensitivity.

float QCamera::manualExposureTime() const

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

Getter function for property manualExposureTime.

See Also

float QCamera::maximumExposureTime() const

The maximal exposure time in seconds.

int QCamera::maximumIsoSensitivity() const

Returns the maximum ISO sensitivity supported by the camera.

float QCamera::minimumExposureTime() const

The minimal exposure time in seconds.

int QCamera::minimumIsoSensitivity() const

Returns the minimum ISO sensitivity supported by the camera.

void QCamera::setActive(bool active)

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

Setter function for property active.

See Also

See also isActive()

void QCamera::setAutoExposureTime()

Use automatically calculated exposure time

void QCamera::setAutoIsoSensitivity()

Turn on auto sensitivity

void QCamera::setCameraDevice(const QCameraDevice &cameraDevice)

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.

Setter function for property cameraDevice.

See Also

See also cameraDevice()

void QCamera::setCameraFormat(const QCameraFormat &format)

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

Setter function for property cameraFormat.

See Also

See also cameraFormat()

void QCamera::setColorTemperature(int colorTemperature)

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 function for property colorTemperature.

See Also

See also colorTemperature()

void QCamera::setWhiteBalanceMode(QCamera::WhiteBalanceMode mode)

Sets the white balance to mode.

Setter function for property whiteBalanceMode.

See Also

See also whiteBalanceMode()

void QCamera::setZoomFactor(float factor)

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

Setter function for property zoomFactor.

See Also

See also zoomFactor()

void QCamera::start()

Starts the camera.

Same as setActive(true).

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

void QCamera::stop()

Stops the camera. Same as setActive(false).

void QCamera::zoomTo(float factor, float rate)

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.

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

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+