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>
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).
- Author
- Phil Schatzmann
- Copyright
- GPLv3
◆ CameraFrameSourceOpenCV() [1/2]
◆ CameraFrameSourceOpenCV() [2/2]
- Parameters
-
| device | cv::VideoCapture index (e.g. 0 for /dev/video0) |
◆ begin()
Opens the capture device (cv::VideoCapture::open()), applies any width/height/fps requested via setVideoInfo(), then reads back the values actually in effect.
◆ end()
Releases the capture device.
◆ nextFrame()
| const uint8_t * nextFrame |
( |
size_t & |
len | ) |
|
|
inlineoverridevirtual |
◆ setApiPreference()
| void setApiPreference |
( |
int |
api | ) |
|
|
inline |
Selects the capture backend (e.g. cv::CAP_V4L2) - default cv::CAP_ANY lets OpenCV pick. Call before begin().
◆ setDevice()
| void setDevice |
( |
const char * |
device | ) |
|
|
inline |
Use a device path/URL/GStreamer pipeline (cv::VideoCapture(const
String&)) instead of a numeric index - call before begin().
◆ setJpegQuality()
| void setJpegQuality |
( |
int |
quality | ) |
|
|
inline |
◆ setVideoInfo()
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().
◆ videoInfo()
◆ writeTo()
| bool writeTo |
( |
Print & |
out | ) |
|
|
inlineinherited |
Write the frame to the indicated destination.
◆ api_preference
| int api_preference = cv::CAP_ANY |
|
protected |
◆ cap
◆ device_index
◆ device_string
| const char* device_string = nullptr |
|
protected |
◆ frame
◆ info
◆ jpeg_buffer
| std::vector<uint8_t> jpeg_buffer |
|
protected |
◆ jpeg_quality
The documentation for this class was generated from the following file: