|
arduino-audio-tools
|
VideoFrameSource that pulls frames from an OpenCV cv::VideoCapture (e.g. a USB/CSI webcam via V4L2 on Linux/Raspberry Pi, or any other OpenCV-supported backend) - the desktop/Linux counterpart to CameraFrameSource, which targets the ESP32 esp_camera.h driver instead. More...
#include <CameraFrameSourceOpenCV.h>


Public Member Functions | |
| CameraFrameSourceOpenCV ()=default | |
| CameraFrameSourceOpenCV (int device) | |
| bool | begin () |
| void | end () |
| Releases the capture device. | |
| const uint8_t * | nextFrame (size_t &len) override |
| void | setApiPreference (int api) |
| void | setDevice (const char *device) |
| void | setJpegQuality (int quality) |
| void | setVideoInfo (VideoInfo info) |
| VideoInfo | videoInfo () override |
| bool | writeTo (Print &out) |
| Write the frame to the indicated destination. | |
Protected Attributes | |
| int | api_preference = cv::CAP_ANY |
| cv::VideoCapture | cap |
| int | device_index = 0 |
| const char * | device_string = nullptr |
| cv::Mat | frame |
| VideoInfo | info |
| std::vector< uint8_t > | jpeg_buffer |
| int | jpeg_quality = 90 |
VideoFrameSource that pulls frames from an OpenCV cv::VideoCapture (e.g. a USB/CSI webcam via V4L2 on Linux/Raspberry Pi, or any other OpenCV-supported backend) - the desktop/Linux counterpart to CameraFrameSource, which targets the ESP32 esp_camera.h driver instead.
nextFrame() grabs a picture with cv::VideoCapture::read() and, by default (videoInfo().format == VideoFormat::MJPEG), JPEG-encodes it via cv::imencode() so the result matches CameraFrameSource's own already-encoded-JPEG contract. setVideoInfo() with VideoFormat::RAW instead returns the picture as captured - OpenCV's native 3 bytes/pixel BGR layout, which is what VideoFormat::RAW itself denotes - with no re-encoding, e.g. to feed a VideoEncoder (H264Encoder) directly. As with any VideoFrameSource, the returned pointer is only valid until the next nextFrame() call.
width/height/fps are read back from the capture device in begin() - set them beforehand via setVideoInfo()/the constructor to request specific values from cv::VideoCapture (best effort; not all backends/devices honor every value, so the actually-applied values are what ends up in videoInfo() afterwards).
|
default |
|
inline |
| device | cv::VideoCapture index (e.g. 0 for /dev/video0) |
|
inline |
Opens the capture device (cv::VideoCapture::open()), applies any width/height/fps requested via setVideoInfo(), then reads back the values actually in effect.
|
inline |
Releases the capture device.
Captures a new picture and, unless videoInfo().format is VideoFormat::RAW, JPEG-encodes it - nullptr (len 0) if the capture failed.
Implements VideoFrameSource.
|
inline |
Selects the capture backend (e.g. cv::CAP_V4L2) - default cv::CAP_ANY lets OpenCV pick. Call before begin().
|
inline |
Use a device path/URL/GStreamer pipeline (cv::VideoCapture(const String&)) instead of a numeric index - call before begin().
|
inline |
JPEG quality (0-100) used to encode frames when videoInfo().format is VideoFormat::MJPEG (the default) - see cv::IMWRITE_JPEG_QUALITY.
|
inline |
Requests width/height/fps/format from the capture device - all optional (0/UNKNOWN = leave the device's own default); actually applied on a best-effort basis in begin() via cv::VideoCapture::set(). format only selects nextFrame()'s own output (see class comment), it is not passed to OpenCV. Call before begin().
|
inlineoverridevirtual |
Provides the width/height/fps/format determined in begin() (or requested explicitly beforehand via setVideoInfo() - see there).
Implements VideoFrameSource.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |