WPILibC++  2020.3.2-60-g3011ebe
cs::RawCvSink Class Reference

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

#include <cscore_raw_cv.h>

Inheritance diagram for cs::RawCvSink:

Public Member Functions

 RawCvSink (const wpi::Twine &name)
 Create a sink for accepting OpenCV images. More...
 
 RawCvSink (const wpi::Twine &name, std::function< void(uint64_t time)> processFrame)
 Create a sink for accepting OpenCV images in a separate thread. More...
 
uint64_t GrabFrame (cv::Mat &image, double timeout=0.225)
 Wait for the next frame and get the image. More...
 
uint64_t GrabFrameNoTimeout (cv::Mat &image)
 Wait for the next frame and get the image. More...
 
uint64_t GrabFrameDirect (cv::Mat &image, double timeout=0.225)
 Wait for the next frame and get the image. More...
 
uint64_t GrabFrameNoTimeoutDirect (cv::Mat &image)
 Wait for the next frame and get the image. More...
 

Detailed Description

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

If you are using the WPILib OpenCV builds, do not use this, and instead include "cscore_cv.h" to get a more performant version.

This is not dependent on any opencv binary ABI, and can be used with versions of OpenCV that are not 3. If using OpenCV 3, use CvSink.

Constructor & Destructor Documentation

◆ RawCvSink() [1/2]

cs::RawCvSink::RawCvSink ( const wpi::Twine name)
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)

◆ RawCvSink() [2/2]

cs::RawCvSink::RawCvSink ( const wpi::Twine name,
std::function< void(uint64_t time)>  processFrame 
)
inline

Create a sink for accepting OpenCV 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 cs::RawCvSink::GrabFrame ( cv::Mat &  image,
double  timeout = 0.225 
)
inline

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

◆ GrabFrameDirect()

uint64_t cs::RawCvSink::GrabFrameDirect ( cv::Mat &  image,
double  timeout = 0.225 
)
inline

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

◆ GrabFrameNoTimeout()

uint64_t cs::RawCvSink::GrabFrameNoTimeout ( cv::Mat &  image)
inline

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

◆ GrabFrameNoTimeoutDirect()

uint64_t cs::RawCvSink::GrabFrameNoTimeoutDirect ( cv::Mat &  image)
inline

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

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