Singleton webcam capture using Qt6 Multimedia.
More...
#include <webcam_capture.h>
|
| bool | startCapture (int width=640, int height=480) |
| | Start capturing from the default camera.
|
|
void | stopCapture () |
| | Stop capturing.
|
| bool | getLatestFrame (uint8_t *dest, int width, int height) |
| | Copy the latest webcam frame into the destination buffer as RGB24, scaled to the requested dimensions.
|
| bool | isActive () const |
| | Check if the camera is actively capturing.
|
|
|
| WebcamCapture () |
| | Private constructor (singleton).
|
|
|
std::unique_ptr< QCamera > | m_camera |
| | The camera device.
|
|
std::unique_ptr< QMediaCaptureSession > | m_session |
| | The capture session.
|
|
std::unique_ptr< QVideoSink > | m_sink |
| | The video sink.
|
|
QImage | m_latestFrame |
| | Latest captured frame as RGB888 QImage.
|
|
std::mutex | m_mutex |
| | Mutex protecting m_latestFrame.
|
|
bool | m_active = false |
| | Whether capture is active.
|
Singleton webcam capture using Qt6 Multimedia.
Only one instance is created (first user). Multiple StreamGenerators can read the latest frame concurrently via getLatestFrame().
◆ getLatestFrame()
| bool WebcamCapture::getLatestFrame |
( |
uint8_t * | dest, |
|
|
int | width, |
|
|
int | height ) |
Copy the latest webcam frame into the destination buffer as RGB24, scaled to the requested dimensions.
- Parameters
-
| dest | Destination buffer (must be at least width*height*3 bytes) |
| width | Target width |
| height | Target height |
- Returns
- true if a frame was available and copied
◆ instance()
Get the singleton instance (created on first call).
- Returns
- WebcamCapture*
◆ isActive()
| bool WebcamCapture::isActive |
( |
| ) |
const |
Check if the camera is actively capturing.
- Returns
- true if active
◆ onVideoFrameChanged
| void WebcamCapture::onVideoFrameChanged |
( |
const QVideoFrame & | frame | ) |
|
|
privateslot |
Receive a new video frame from the camera.
- Parameters
-
◆ startCapture()
| bool WebcamCapture::startCapture |
( |
int | width = 640, |
|
|
int | height = 480 ) |
Start capturing from the default camera.
- Parameters
-
| width | Desired capture width |
| height | Desired capture height |
- Returns
- true if camera started successfully
The documentation for this class was generated from the following files: