WPILibC++ 2025.3.1
Loading...
Searching...
No Matches
cs::CvSink Class Reference

A source for user code to accept video frames as OpenCV images. More...

#include <cscore_cv.h>

Inheritance diagram for cs::CvSink:
cs::ImageSink cs::VideoSink

Public Member Functions

 CvSink ()=default
 
 CvSink (const CvSink &sink)
 
 CvSink (std::string_view name, VideoMode::PixelFormat pixelFormat=VideoMode::PixelFormat::kBGR)
 Create a sink for accepting OpenCV images.
 
uint64_t GrabFrame (cv::Mat &image, double timeout=0.225)
 Wait for the next frame and get the image.
 
uint64_t GrabFrameNoTimeout (cv::Mat &image)
 Wait for the next frame and get the image.
 
uint64_t GrabFrameDirect (cv::Mat &image, double timeout=0.225)
 Wait for the next frame and get the image.
 
uint64_t GrabFrameNoTimeoutDirect (cv::Mat &image)
 Wait for the next frame and get the image.
 
uint64_t GrabFrameDirectLastTime (cv::Mat &image, uint64_t lastFrameTime, double timeout=0.225)
 Wait for the next frame and get the image.
 
uint64_t LastFrameTime ()
 Get the last time a frame was grabbed.
 
WPI_TimestampSource LastFrameTimeSource ()
 Get the time source for the timestamp the last frame was grabbed at.
 
- Public Member Functions inherited from cs::ImageSink
void SetDescription (std::string_view description)
 Set sink description.
 
std::string GetError () const
 Get error string.
 
void SetEnabled (bool enabled)
 Enable or disable getting new frames.
 
- Public Member Functions inherited from cs::VideoSink
 VideoSink () noexcept=default
 
 VideoSink (const VideoSink &sink)
 
 VideoSink (VideoSink &&other) noexcept
 
VideoSinkoperator= (VideoSink other) noexcept
 
 ~VideoSink ()
 
 operator bool () const
 Returns true if the VideoSink is valid.
 
int GetHandle () const
 Returns the VideoSink handle.
 
bool operator== (const VideoSink &other) const
 
Kind GetKind () const
 Get the kind of the sink.
 
std::string GetName () const
 Get the name of the sink.
 
std::string GetDescription () const
 Get the sink description.
 
VideoProperty GetProperty (std::string_view name)
 Get a property of the sink.
 
std::vector< VideoPropertyEnumerateProperties () const
 Enumerate all properties of this sink.
 
bool SetConfigJson (std::string_view config)
 Set properties from a JSON configuration string.
 
bool SetConfigJson (const wpi::json &config)
 Set properties from a JSON configuration object.
 
std::string GetConfigJson () const
 Get a JSON configuration string.
 
wpi::json GetConfigJsonObject () const
 Get a JSON configuration object.
 
void SetSource (VideoSource source)
 Configure which source should provide frames to this sink.
 
VideoSource GetSource () const
 Get the connected source.
 
VideoProperty GetSourceProperty (std::string_view name)
 Get a property of the associated source.
 
CS_Status GetLastStatus () const
 

Additional Inherited Members

- Public Types inherited from cs::VideoSink
enum  Kind { kUnknown = CS_SINK_UNKNOWN , kMjpeg = CS_SINK_MJPEG , kCv = CS_SINK_CV , kRaw = CS_SINK_RAW }
 
- Static Public Member Functions inherited from cs::VideoSink
static std::vector< VideoSinkEnumerateSinks ()
 Enumerate all existing sinks.
 
- Protected Member Functions inherited from cs::ImageSink
 ImageSink ()=default
 
- Protected Member Functions inherited from cs::VideoSink
 VideoSink (CS_Sink handle)
 
- Protected Attributes inherited from cs::VideoSink
CS_Status m_status = 0
 
CS_Sink m_handle {0}
 

Detailed Description

A source for user code to accept video frames as OpenCV images.

This is not dependent on any opencv binary ABI, and can be used with versions of most versions of OpenCV.

Constructor & Destructor Documentation

◆ CvSink() [1/3]

cs::CvSink::CvSink ( )
default

◆ CvSink() [2/3]

cs::CvSink::CvSink ( const CvSink & sink)
inline

◆ CvSink() [3/3]

cs::CvSink::CvSink ( std::string_view name,
VideoMode::PixelFormat pixelFormat = VideoMode::PixelFormat::kBGR )
inlineexplicit

Create a sink for accepting OpenCV images.

WaitForFrame() must be called on the created sink to get each new image.

Parameters
nameSource name (arbitrary unique identifier)
pixelFormatThe pixel format to read

Member Function Documentation

◆ GrabFrame()

uint64_t cs::CvSink::GrabFrame ( cv::Mat & image,
double timeout = 0.225 )
inlinenodiscard

Wait for the next frame and get the image.

Times out (returning 0) after timeout seconds. The provided image will have the pixelFormat this class was constructed with.

Returns
Frame time, or 0 on error (call GetError() to obtain the error message); the frame time is in the same time base as wpi::Now(), and is in 1 us increments.

◆ GrabFrameDirect()

uint64_t cs::CvSink::GrabFrameDirect ( cv::Mat & image,
double timeout = 0.225 )
inlinenodiscard

Wait for the next frame and get the image.

Times out (returning 0) after timeout seconds. The provided image will have the pixelFormat this class was constructed with. The data is backed by data in the CvSink. It will be invalidated by any grabFrame*() call on the sink.

Returns
Frame time, or 0 on error (call GetError() to obtain the error message); the frame time is in the same time base as wpi::Now(), and is in 1 us increments.

◆ GrabFrameDirectLastTime()

uint64_t cs::CvSink::GrabFrameDirectLastTime ( cv::Mat & image,
uint64_t lastFrameTime,
double timeout = 0.225 )
inlinenodiscard

Wait for the next frame and get the image.

Times out (returning 0) after timeout seconds. The provided image will have the pixelFormat this class was constructed with. The data is backed by data in the CvSink. It will be invalidated by any grabFrame*() call on the sink.

If lastFrameTime is provided and non-zero, the sink will fill image with the first frame from the source that is not equal to lastFrameTime. If lastFrameTime is zero, the time of the current frame owned by the CvSource is used, and this function will block until the connected CvSource provides a new frame.

Returns
Frame time, or 0 on error (call GetError() to obtain the error message); the frame time is in the same time base as wpi::Now(), and is in 1 us increments.

◆ GrabFrameNoTimeout()

uint64_t cs::CvSink::GrabFrameNoTimeout ( cv::Mat & image)
inlinenodiscard

Wait for the next frame and get the image.

May block forever. The provided image will have the pixelFormat this class was constructed with.

Returns
Frame time, or 0 on error (call GetError() to obtain the error message); the frame time is in the same time base as wpi::Now(), and is in 1 us increments.

◆ GrabFrameNoTimeoutDirect()

uint64_t cs::CvSink::GrabFrameNoTimeoutDirect ( cv::Mat & image)
inlinenodiscard

Wait for the next frame and get the image.

May block forever. The provided image will have the pixelFormat this class was constructed with. The data is backed by data in the CvSink. It will be invalidated by any grabFrame*() call on the sink.

Returns
Frame time, or 0 on error (call GetError() to obtain the error message); the frame time is in the same time base as wpi::Now(), and is in 1 us increments.

◆ LastFrameTime()

uint64_t cs::CvSink::LastFrameTime ( )
inlinenodiscard

Get the last time a frame was grabbed.

This uses the same time base as wpi::Now().

Returns
Time in 1 us increments.

◆ LastFrameTimeSource()

WPI_TimestampSource cs::CvSink::LastFrameTimeSource ( )
inlinenodiscard

Get the time source for the timestamp the last frame was grabbed at.

Returns
Time source

The documentation for this class was generated from the following file: