VisionServer  v2.1.1-1-g21dc5465
FRC vision library
VisionCamera Class Referencefinal

#include <visioncamera.h>

+ Inheritance diagram for VisionCamera:
+ Collaboration diagram for VisionCamera:

Public Member Functions

 VisionCamera (CS_Source source_handle)
 
 VisionCamera (const cs::VideoSource &source, const wpi::json &config=wpi::json())
 
 VisionCamera (const cs::UsbCamera &source, const wpi::json &config=wpi::json())
 
 VisionCamera (const cs::HttpCamera &source, const wpi::json &config=wpi::json())
 
 VisionCamera (const wpi::json &source_config, const wpi::json &calibration)
 
 VisionCamera (const wpi::json &source_config)
 
 VisionCamera (const VisionCamera &)=delete
 
 VisionCamera (VisionCamera &&)
 
 ~VisionCamera ()
 
VisionCameraoperator= (const VisionCamera &)=delete
 
VisionCameraoperator= (VisionCamera &&)
 
bool isValidJson () const
 
const wpi::json & getJson () const
 
bool isValidStreamJson () const
 
wpi::json getStreamJson () const
 
bool getJsonCameraMatrix (cv::Mat_< double > &array) const
 
bool getJsonCameraMatrix (cv::Mat_< float > &array) const
 
bool getJsonDistortionCoefs (cv::Mat_< double > &array) const
 
bool getJsonDistortionCoefs (cv::Mat_< float > &array) const
 
const cv::Mat_< float > & getCameraMatrix () const
 
const cv::Mat_< float > & getDistortionCoefs () const
 
bool setCalibrationJson (const wpi::json &)
 
bool setCameraMatrix (const cv::Mat_< float > &)
 
bool setDistortionCoefs (const cv::Mat_< float > &)
 
uint64_t getFrame (cv::Mat &o_frame, double timeout=0.225) const
 
uint64_t getFrameNoTmO (cv::Mat &o_frame) const
 
const cs::CvSink & getSink () const
 
int getWidth () const
 
int getHeight () const
 
int getPixels () const
 
int getConfigFPS () const
 
cv::Size getResolution () const
 
int getBrightness () const
 
int getExposure () const
 
int getWhiteBalance () const
 
void setBrightness (int b)
 
void setWhiteBalance (int wb)
 
void setExposure (int e)
 
void setNetworkBase (const std::shared_ptr< nt::NetworkTable > &table)
 
void setNetworkAdjustable ()
 

Static Public Attributes

static const cv::Mat_< float > default_matrix {cv::Mat_<float>::zeros(3, 3)}
 
static const cv::Mat_< float > default_distort {cv::Mat_<float>::zeros(1, 5)}
 

Protected Member Functions

int _setBrightness (int b)
 
int _setWhiteBalance (int wb)
 
int _setExposure (int e)
 

Private Attributes

wpi::json config
 
wpi::json calibration
 
cs::CvSink raw
 
cv::Mat_< float > camera_matrix {default_matrix}
 
cv::Mat_< float > distortion {default_distort}
 
cs::VideoMode properties
 
std::shared_ptr< nt::NetworkTable > ntable
 
nt::IntegerEntry nt_brightness
 
nt::IntegerEntry nt_exposure
 
nt::IntegerEntry nt_whitebalance
 
NT_Listener listener_handle {0}
 

Detailed Description

Adds extra functionality and ease of use on top of cs::VideoCaemra (base of cs::HTTPCamera and cs::UsbCamera)

Definition at line 15 of file visioncamera.h.

Constructor & Destructor Documentation

◆ VisionCamera() [1/8]

VisionCamera::VisionCamera ( CS_Source  source_handle)

Construct from a raw cscore source handle

Parameters
source_handleA cscore source handle for a camera

Definition at line 9 of file visioncamera.cpp.

◆ VisionCamera() [2/8]

VisionCamera::VisionCamera ( const cs::VideoSource &  source,
const wpi::json &  config = wpi::json() 
)

Construct from a VideoSource and optional config json

Parameters
sourceThe source object that will be copied from
configThe config json for the camera

Definition at line 14 of file visioncamera.cpp.

◆ VisionCamera() [3/8]

VisionCamera::VisionCamera ( const cs::UsbCamera &  source,
const wpi::json &  config = wpi::json() 
)

Construct from a UsbCamera and optional config json - SEEMINGLY NOT FUNCTIONAL

Parameters
sourceThe source object that will be copied from
configThe config json for the camera

Definition at line 20 of file visioncamera.cpp.

◆ VisionCamera() [4/8]

VisionCamera::VisionCamera ( const cs::HttpCamera &  source,
const wpi::json &  config = wpi::json() 
)

Construct from a HttpCamera and optional config json - SEEMINGLY NOT FUNCTIONAL

Parameters
sourceThe source object that will be copied from
configThe config json for the camera

Definition at line 26 of file visioncamera.cpp.

◆ VisionCamera() [5/8]

VisionCamera::VisionCamera ( const wpi::json &  source_config,
const wpi::json &  calibration 
)

Construct using json configuration and calibration blocks

Parameters
source_configThe camera configuration json object
calibrationThe json object containing calibration values for the camera

Definition at line 32 of file visioncamera.cpp.

◆ VisionCamera() [6/8]

VisionCamera::VisionCamera ( const wpi::json &  source_config)

Construct using json configuration without camera calibration

Parameters
source_configThe camera configuration json object

Definition at line 51 of file visioncamera.cpp.

◆ VisionCamera() [7/8]

VisionCamera::VisionCamera ( const VisionCamera )
delete

◆ VisionCamera() [8/8]

VisionCamera::VisionCamera ( VisionCamera &&  other)

Definition at line 71 of file visioncamera.cpp.

◆ ~VisionCamera()

VisionCamera::~VisionCamera ( )

Deletes all networktable entries for the camera's subtable

Definition at line 88 of file visioncamera.cpp.

Member Function Documentation

◆ operator=() [1/2]

VisionCamera & VisionCamera::operator= ( const VisionCamera )
inlinedelete

◆ operator=() [2/2]

VisionCamera & VisionCamera::operator= ( VisionCamera &&  other)

Definition at line 102 of file visioncamera.cpp.

◆ isValidJson()

bool VisionCamera::isValidJson ( ) const

Get if the cameras calibration json is valid

Returns
Whether or not the calibration json is valid

Definition at line 123 of file visioncamera.cpp.

◆ getJson()

const wpi::json & VisionCamera::getJson ( ) const

Get the calibration json

Returns
The calibration json object

Definition at line 126 of file visioncamera.cpp.

◆ isValidStreamJson()

bool VisionCamera::isValidStreamJson ( ) const

Get the config contains a stream configuration

Returns
Whether or not the config json has a stream configuration block

Definition at line 129 of file visioncamera.cpp.

◆ getStreamJson()

wpi::json VisionCamera::getStreamJson ( ) const

Get the stream configuration json

Returns
A stream configuration json block - returns an empty wpi::json on error (isValidStreamJson() is false)

Definition at line 132 of file visioncamera.cpp.

◆ getJsonCameraMatrix() [1/2]

bool VisionCamera::getJsonCameraMatrix ( cv::Mat_< double > &  array) const

Get the camera's matrix array (doubles) - parsed from json

Parameters
arrayAn output array that will be set to the camera's matrix values - size is 3x3 (double)
Returns
Whether or not the array could be successfully filled

Definition at line 139 of file visioncamera.cpp.

◆ getJsonCameraMatrix() [2/2]

bool VisionCamera::getJsonCameraMatrix ( cv::Mat_< float > &  array) const

Get the camera's matrix array (floats) - parsed from json

Parameters
arrayAn output array that will be set to the camera's matrix values - size is 3x3 (float)
Returns
Whether or not the array could be successfully filled

Definition at line 155 of file visioncamera.cpp.

◆ getJsonDistortionCoefs() [1/2]

bool VisionCamera::getJsonDistortionCoefs ( cv::Mat_< double > &  array) const

Get the camera's distortion coefficients (doubles) - parsed from json

Parameters
arrayAn output array that will be set to the camera's distortion coefficients - size is 5x1 (double)
Returns
Whether or not the array coulb be successfully filled

Definition at line 171 of file visioncamera.cpp.

◆ getJsonDistortionCoefs() [2/2]

bool VisionCamera::getJsonDistortionCoefs ( cv::Mat_< float > &  array) const

Get the camera's distortion coefficients (floats) - parsed from json

Parameters
arrayAn output array that will be set to the camera's distortion coefficients - size is 5x1 (float)
Returns
Whether or not the array could be successfully filled

Definition at line 185 of file visioncamera.cpp.

◆ getCameraMatrix()

const cv::Mat_< float > & VisionCamera::getCameraMatrix ( ) const
inline

Get the internally stored camera matrix

Returns
a const reference to the internal matrix

Definition at line 120 of file visioncamera.h.

◆ getDistortionCoefs()

const cv::Mat_< float > & VisionCamera::getDistortionCoefs ( ) const
inline

Get the internally stored distortion coefficient matrix

Returns
a const reference to the internal matrix

Definition at line 125 of file visioncamera.h.

◆ setCalibrationJson()

bool VisionCamera::setCalibrationJson ( const wpi::json &  j)

Definition at line 200 of file visioncamera.cpp.

◆ setCameraMatrix()

bool VisionCamera::setCameraMatrix ( const cv::Mat_< float > &  mat)

Definition at line 209 of file visioncamera.cpp.

◆ setDistortionCoefs()

bool VisionCamera::setDistortionCoefs ( const cv::Mat_< float > &  mat)

Definition at line 216 of file visioncamera.cpp.

◆ getFrame()

uint64_t VisionCamera::getFrame ( cv::Mat &  o_frame,
double  timeout = 0.225 
) const

Wraps cs::CvSink::GrabFrame() for the internal sink. If the camera is not physically connected, the buffer is set to a blank frame

Parameters
o_framethe output framebuffer
timeoutmaximum time that the thread with block until returning with an empty frame
Returns
the frametime, in 1 microsecond increments (see wpi::Now())

Definition at line 224 of file visioncamera.cpp.

◆ getFrameNoTmO()

uint64_t VisionCamera::getFrameNoTmO ( cv::Mat &  o_frame) const

Wraps cs::CvSink::GrabFrameNoTimeout() for the internal sink. If the camera is not phystically connected, the buffer is set to a blank frame

Parameters
o_framethe output framebuffer
Returns
the frametime, in 1 microsecond increments (see wpi::Now())

Definition at line 232 of file visioncamera.cpp.

◆ getSink()

const cs::CvSink & VisionCamera::getSink ( ) const
inline

Get the internal CvSink for aquiring frames from the camera

Returns
a const reference to the internal sink

Definition at line 148 of file visioncamera.h.

◆ getWidth()

int VisionCamera::getWidth ( ) const

Get the width of a frame output by the camera

Returns
The width in pixels

Definition at line 241 of file visioncamera.cpp.

◆ getHeight()

int VisionCamera::getHeight ( ) const

Get the height of a frame output by the camera

Returns
The height in pixels

Definition at line 244 of file visioncamera.cpp.

◆ getPixels()

int VisionCamera::getPixels ( ) const

Get the total number of pixels in each frame (width x height)

Returns
The total number of pixels in each frame

Definition at line 247 of file visioncamera.cpp.

◆ getConfigFPS()

int VisionCamera::getConfigFPS ( ) const

Get the current fps the camera is set to capture at

Returns
The fps

Definition at line 251 of file visioncamera.cpp.

◆ getResolution()

cv::Size VisionCamera::getResolution ( ) const

Get the width and height of a camera frame in cv::Size format

Returns
The resolution of a camera frame in a cv::Size object

Definition at line 254 of file visioncamera.cpp.

◆ getBrightness()

int VisionCamera::getBrightness ( ) const

Get the current brightness setting for the camera

Returns
The brightness (0-100, -1 for auto)

Definition at line 258 of file visioncamera.cpp.

◆ getExposure()

int VisionCamera::getExposure ( ) const

Get the current exposure setting for the camera

Returns
The exposure (0-100, -1 for auto)

Definition at line 261 of file visioncamera.cpp.

◆ getWhiteBalance()

int VisionCamera::getWhiteBalance ( ) const

Get the current whitebalance setting for the camera

Returns
The whitebalance (0-??? (>7000), -1 for auto)

Definition at line 264 of file visioncamera.cpp.

◆ setBrightness()

void VisionCamera::setBrightness ( int  b)

Set the brightness of the camera

Parameters
bThe brightness (0-100, -1 for auto)

Definition at line 268 of file visioncamera.cpp.

◆ setWhiteBalance()

void VisionCamera::setWhiteBalance ( int  wb)

Set the whitebalance of the camera

Parameters
wbThe whitebalance (0-???, -1 for auto)

Definition at line 271 of file visioncamera.cpp.

◆ setExposure()

void VisionCamera::setExposure ( int  e)

Set the exposure of the camera

Parameters
eThe exposure (0-100, -1 for auto)

Definition at line 274 of file visioncamera.cpp.

◆ setNetworkBase()

void VisionCamera::setNetworkBase ( const std::shared_ptr< nt::NetworkTable > &  table)

Set the root networktable in which the camera's own networktable should reside

Parameters
tableThe root table (the camera resides in ~table~/Cameras)

Definition at line 278 of file visioncamera.cpp.

◆ setNetworkAdjustable()

void VisionCamera::setNetworkAdjustable ( )

Publish networktables-adjustable settings for exposure, brightness, and whitebalance under the camera's networktable

Definition at line 281 of file visioncamera.cpp.

◆ _setBrightness()

int VisionCamera::_setBrightness ( int  b)
protected

Definition at line 314 of file visioncamera.cpp.

◆ _setWhiteBalance()

int VisionCamera::_setWhiteBalance ( int  wb)
protected

Definition at line 319 of file visioncamera.cpp.

◆ _setExposure()

int VisionCamera::_setExposure ( int  e)
protected

Definition at line 323 of file visioncamera.cpp.

Member Data Documentation

◆ default_matrix

const cv::Mat_<float> VisionCamera::default_matrix {cv::Mat_<float>::zeros(3, 3)}
inlinestatic

Definition at line 18 of file visioncamera.h.

◆ default_distort

const cv::Mat_<float> VisionCamera::default_distort {cv::Mat_<float>::zeros(1, 5)}
static

Definition at line 19 of file visioncamera.h.

◆ config

wpi::json VisionCamera::config
private

Definition at line 224 of file visioncamera.h.

◆ calibration

wpi::json VisionCamera::calibration
private

Definition at line 224 of file visioncamera.h.

◆ raw

cs::CvSink VisionCamera::raw
private

Definition at line 225 of file visioncamera.h.

◆ camera_matrix

cv::Mat_<float> VisionCamera::camera_matrix {default_matrix}
private

Definition at line 226 of file visioncamera.h.

◆ distortion

cv::Mat_<float> VisionCamera::distortion {default_distort}
private

Definition at line 226 of file visioncamera.h.

◆ properties

cs::VideoMode VisionCamera::properties
private

Definition at line 227 of file visioncamera.h.

◆ ntable

std::shared_ptr<nt::NetworkTable> VisionCamera::ntable
private
Initial value:
{
nt::NetworkTableInstance::GetDefault().GetTable("Cameras")->GetSubTable(this->GetName())}

Definition at line 229 of file visioncamera.h.

◆ nt_brightness

nt::IntegerEntry VisionCamera::nt_brightness
private

Definition at line 232 of file visioncamera.h.

◆ nt_exposure

nt::IntegerEntry VisionCamera::nt_exposure
private

Definition at line 232 of file visioncamera.h.

◆ nt_whitebalance

nt::IntegerEntry VisionCamera::nt_whitebalance
private

Definition at line 232 of file visioncamera.h.

◆ listener_handle

NT_Listener VisionCamera::listener_handle {0}
private

Definition at line 233 of file visioncamera.h.


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