BoB robotics
The Brains on Board robotics library
BoBRobotics::Video::OpenCVInput Class Reference

A thin wrapper for reading from any video source supported by OpenCV. More...

#include <opencvinput.h>

Inheritance diagram for BoBRobotics::Video::OpenCVInput:
BoBRobotics::Video::Input

Public Member Functions

 OpenCVInput ()
 Create a new video stream, using the default given by OpenCV.
 
template<class T >
 OpenCVInput (T device, const std::string &cameraName=DefaultCameraName)
 Create a video stream for a specific device. More...
 
template<class T >
 OpenCVInput (T device, const cv::Size &outSize, const std::string &cameraName=DefaultCameraName)
 Create a video stream for a specific device and a specified resolution. More...
 
virtual std::string getCameraName () const override
 Get the name of this type of camera as a (short) string. More...
 
virtual cv::Size getOutputSize () const override
 Get the current output resolution of this video stream. More...
 
virtual units::frequency::hertz_t getFrameRate () const override
 
virtual bool readFrame (cv::Mat &outFrame) override
 Try to read a frame in colour from this video source. More...
 
virtual void setOutputSize (const cv::Size &outSize) override
 Set the output resolution of this video stream. More...
 
- Public Member Functions inherited from BoBRobotics::Video::Input
ImgProc::OpenCVUnwrap360 createUnwrapper (const cv::Size &unwrapRes) const
 Create an ImgProc::OpenCVUnwrap360 object for this video stream. More...
 
virtual std::string getCameraName () const
 Get the name of this type of camera as a (short) string. More...
 
virtual units::frequency::hertz_t getFrameRate () const
 
virtual cv::Size getOutputSize () const =0
 Get the current output resolution of this video stream. More...
 
virtual bool needsUnwrapping () const
 Whether this video source needs unwrapping with an ImgProc::OpenCVUnwrap360. More...
 
virtual void setOutputSize (const cv::Size &)
 Set the output resolution of this video stream. More...
 
virtual bool readFrame (cv::Mat &outFrame)=0
 Try to read a frame in colour from this video source. More...
 
virtual bool readGreyscaleFrame (cv::Mat &outFrame)
 Try to read a frame in greyscale from this video source. More...
 
void readFrameSync (cv::Mat &outFrame)
 Read a frame synchronously, blocking until a new frame is received.
 
void readGreyscaleFrameSync (cv::Mat &outFrame)
 
void write (cv::FileStorage &fs) const
 Allows OpenCV to serialise info about this Input.
 

Additional Inherited Members

- Static Public Attributes inherited from BoBRobotics::Video::Input
static constexpr const char * DefaultCameraName = "unknown_camera"
 

Detailed Description

A thin wrapper for reading from any video source supported by OpenCV.

Constructor & Destructor Documentation

◆ OpenCVInput() [1/2]

template<class T >
BoBRobotics::Video::OpenCVInput::OpenCVInput ( device,
const std::string &  cameraName = DefaultCameraName 
)
inline

Create a video stream for a specific device.

Parameters
deviceInteger or string representation of device (passed to cv::VideoCapture's constructor)
cameraNameThe short name to use for this camera (see getCameraName())

◆ OpenCVInput() [2/2]

template<class T >
BoBRobotics::Video::OpenCVInput::OpenCVInput ( device,
const cv::Size &  outSize,
const std::string &  cameraName = DefaultCameraName 
)
inline

Create a video stream for a specific device and a specified resolution.

Parameters
deviceInteger or string representation of device (passed to cv::VideoCapture's constructor)
outSizeOutput resolution of camera
cameraNameThe short name to use for this camera (see getCameraName())

Member Function Documentation

◆ getCameraName()

std::string BoBRobotics::Video::OpenCVInput::getCameraName ( ) const
overridevirtual

Get the name of this type of camera as a (short) string.

Note that this is used to load the appropriate unwrapping parameters (we look for a file called [camera name].yaml).

Reimplemented from BoBRobotics::Video::Input.

◆ getFrameRate()

units::frequency::hertz_t BoBRobotics::Video::OpenCVInput::getFrameRate ( ) const
overridevirtual

Reimplemented from BoBRobotics::Video::Input.

◆ getOutputSize()

cv::Size BoBRobotics::Video::OpenCVInput::getOutputSize ( ) const
overridevirtual

Get the current output resolution of this video stream.

Implements BoBRobotics::Video::Input.

◆ readFrame()

bool BoBRobotics::Video::OpenCVInput::readFrame ( cv::Mat &  outFrame)
overridevirtual

Try to read a frame in colour from this video source.

The output frame should have type CV_8UC3.

Returns
Whether a new frame was read

Implements BoBRobotics::Video::Input.

◆ setOutputSize()

void BoBRobotics::Video::OpenCVInput::setOutputSize ( const cv::Size &  )
overridevirtual

Set the output resolution of this video stream.

Reimplemented from BoBRobotics::Video::Input.


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