WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::cs::RawSink Class Reference

A sink for user code to accept video frames as raw bytes. More...

#include <wpi/cs/RawSink.hpp>

Inheritance diagram for wpi::cs::RawSink:
wpi::cs::ImageSink wpi::cs::VideoSink

Public Member Functions

 RawSink ()=default
 RawSink (std::string_view name)
 Create a sink for accepting raw images.
 RawSink (std::string_view name, std::function< void(uint64_t time)> processFrame)
 Create a sink for accepting raws images in a separate thread.
Public Member Functions inherited from wpi::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 wpi::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::util::json &config)
 Set properties from a JSON configuration object.
std::string GetConfigJson () const
 Get a JSON configuration string.
wpi::util::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

Protected Member Functions

uint64_t GrabFrame (wpi::util::RawFrame &image, double timeout=0.225) const
 Wait for the next frame and get the image.
uint64_t GrabFrameNoTimeout (wpi::util::RawFrame &image) const
 Wait for the next frame and get the image.
uint64_t GrabFrameLastTime (wpi::util::RawFrame &image, uint64_t lastFrameTime, double timeout=0.225) const
 Wait for the next frame and get the image.
Protected Member Functions inherited from wpi::cs::ImageSink
 ImageSink ()=default
Protected Member Functions inherited from wpi::cs::VideoSink
 VideoSink (CS_Sink handle)

Additional Inherited Members

Public Types inherited from wpi::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 wpi::cs::VideoSink
static std::vector< VideoSinkEnumerateSinks ()
 Enumerate all existing sinks.
Protected Attributes inherited from wpi::cs::VideoSink
CS_Status m_status = 0
CS_Sink m_handle {0}

Detailed Description

A sink for user code to accept video frames as raw bytes.

This is a complex API, most cases should use CvSource.

Constructor & Destructor Documentation

◆ RawSink() [1/3]

wpi::cs::RawSink::RawSink ( )
default

◆ RawSink() [2/3]

wpi::cs::RawSink::RawSink ( std::string_view name)
inlineexplicit

Create a sink for accepting raw images.

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

Parameters
nameSource name (arbitrary unique identifier)

◆ RawSink() [3/3]

wpi::cs::RawSink::RawSink ( std::string_view name,
std::function< void(uint64_t time)> processFrame )
inline

Create a sink for accepting raws images in a separate thread.

A thread will be created that calls WaitForFrame() and calls the processFrame() callback each time a new frame arrives.

Parameters
nameSource name (arbitrary unique identifier)
processFrameFrame processing function; will be called with a time=0 if an error occurred. processFrame should call GetImage() or GetError() as needed, but should not call (except in very unusual circumstances) WaitForImage().

Member Function Documentation

◆ GrabFrame()

uint64_t wpi::cs::RawSink::GrabFrame ( wpi::util::RawFrame & image,
double timeout = 0.225 ) const
inlinenodiscardprotected

Wait for the next frame and get the image.

Times out (returning 0) after timeout seconds. The provided image will have three 8-bit channels stored in BGR order.

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::util::Now(), and is in 1 us increments.

◆ GrabFrameLastTime()

uint64_t wpi::cs::RawSink::GrabFrameLastTime ( wpi::util::RawFrame & image,
uint64_t lastFrameTime,
double timeout = 0.225 ) const
inlinenodiscardprotected

Wait for the next frame and get the image.

May block forever. The provided image will have three 8-bit channels stored in BGR order.

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::util::Now(), and is in 1 us increments.

◆ GrabFrameNoTimeout()

uint64_t wpi::cs::RawSink::GrabFrameNoTimeout ( wpi::util::RawFrame & image) const
inlinenodiscardprotected

Wait for the next frame and get the image.

May block forever. The provided image will have three 8-bit channels stored in BGR order.

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::util::Now(), and is in 1 us increments.

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