Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Loading...
Searching...
No Matches
cam::Camera Class Reference

Represents a camera on the rover, from which a video feed can be retrieved. More...

#include <Camera.h>

Public Member Functions

 Camera ()
 Constructs an "empty" Camera.
 
bool open (std::string filename, CameraParams intrinsic_params=CameraParams(), cv::Mat extrinsic_params=cv::Mat())
 Opens a Camera that is not already open.
 
bool open (int camera_id, CameraParams intrinsic_params=CameraParams(), cv::Mat extrinsic_params=cv::Mat())
 Opens a Camera that is not already open.
 
 Camera (std::string filename, std::string name, std::string description="", CameraParams intrinsic_params=CameraParams(), cv::Mat extrinsic_params=cv::Mat())
 Constructs a Camera that will open the given file for input and have the given name and description.
 
 Camera (int camera_id, std::string name, std::string description="", CameraParams intrinsic_params=CameraParams(), cv::Mat extrinsic_params=cv::Mat())
 Constructs a Camera that will open the camera with the given ID and have the given name and description.
 
 Camera (const Camera &other)
 Copy constructor.
 
bool openFromConfigFile (std::string filename)
 Opens the camera using the given configuration file.
 
bool isOpen () const
 Returns true if the camera is open.
 
bool hasNext (uint32_t last_frame_num) const
 Returns true if the Camera object has a frame that is different from the last one the client retrieved.
 
bool next (cv::Mat &frame, uint32_t &frame_num) const
 Retrieves the next frame.
 
bool next (cv::Mat &frame, uint32_t &frame_num, robot::types::datatime_t &frame_time) const
 Retrives the next frame.
 
bool hasIntrinsicParams () const
 Returns true if this camera has associated intrinsic parameters.
 
bool hasExtrinsicParams () const
 Returns true if this camera has associated extrinsic parameters.
 
CameraParams getIntrinsicParams () const
 Returns the associated intrinsic parameters as a CameraParams object.
 
cv::Mat getExtrinsicParams () const
 Returns the associated extrinsic parameters as an OpenCV matrix.
 
std::string getDescription () const
 Returns the description of the camera.
 
std::string getName () const
 Returns the name of the camera.
 
void setName (std::string new_name)
 Updates the name of the camera to the given name.
 
void setDescription (std::string new_description)
 Updates the description of the camera to the given description.
 

Detailed Description

Represents a camera on the rover, from which a video feed can be retrieved.

The Camera class provides an interface for opening a camera attached to the rover, and retrieving frames from it. Additionally, a Camera object contains other information associated with the camera, such as a description, its location on the rover, and its intrinsic camera parameters.

A Camera object provides concurrent access to the camera; that is, the video feed will be updated in a separate thread and a client may retrieve a frame at any time. To avoid getting duplicate frames, there is a concept of a "frame number"; it will be returned upon retrieving a frame, and may be used to check if the current frame held by the Camera is different from the last one the client retrieved. The frame number will be different if two frames (within a reasonable time interval) are different.

Additionally, if copied, Camera objects share ownership over a camera; when the last Camera object is destroyed, the underlying camera will be closed. This means multiple Camera objects may exist at different places in the code that refer to the same underlying camera and share access to it.

Warning
Note that intrinsic and extrinsic parameters are optional for a Camera object; Camera objects that are missing either intrinsic parameters, extrinsic parameters, or both may not be suitable for some computer vision operations. For example, AR tag detection requires intrinsic parameters and cannot be performed without them. Use Camera::hasIntrinsicParams() and Camera::hasExtrinsicParams() to check for the presence of each.

Constructor & Destructor Documentation

◆ Camera() [1/4]

cam::Camera::Camera ( )

Constructs an "empty" Camera.

This constructor is included for convenience. Camera objects constructed with this constructor will not actually access any camera, and Camera::isOpen() will return false. The Camera can be replaced later, or manually opened with the Camera::open() method.

◆ Camera() [2/4]

cam::Camera::Camera ( std::string filename,
std::string name,
std::string description = "",
CameraParams intrinsic_params = CameraParams(),
cv::Mat extrinsic_params = cv::Mat() )

Constructs a Camera that will open the given file for input and have the given name and description.

Parameters
filenameThe file to open and read a video feed from. This may be the name of a video file, or a URI of a video stream. This will be passed to the underlying OpenCV VideoCapture object, so anything supported by VideoCapture is supported here.
nameThe name of the camera. This should ideally be unique, but isn't enforced at this time.
descriptionAn optional description of the camera.

◆ Camera() [3/4]

cam::Camera::Camera ( int camera_id,
std::string name,
std::string description = "",
CameraParams intrinsic_params = CameraParams(),
cv::Mat extrinsic_params = cv::Mat() )

Constructs a Camera that will open the camera with the given ID and have the given name and description.

Parameters
filenameThe file to open and read a video feed from. This may be the name of a video file, or a URI of a video stream. This will be passed to the underlying OpenCV VideoCapture object, so anything supported by VideoCapture is supported here.
nameThe name of the camera. This should ideally be unique, but isn't enforced at this time.
descriptionAn optional description of the camera.

◆ Camera() [4/4]

cam::Camera::Camera ( const Camera & other)

Copy constructor.

A Camera object created through this constructor will share access to the underlying camera with the Camera object it is copying. When all Camera objects sharing access are destroyed, the camera will be closed.

Member Function Documentation

◆ getDescription()

std::string cam::Camera::getDescription ( ) const

Returns the description of the camera.

Note the description is optional, in which case an empty string will be returned.

◆ hasNext()

bool cam::Camera::hasNext ( uint32_t last_frame_num) const

Returns true if the Camera object has a frame that is different from the last one the client retrieved.

Parameters
last_frame_numThe frame number that was returned when retrieving a frame.
Returns
true if there is a new frame (i.e. the current frame number is different than the given one) and false if not.

◆ next() [1/2]

bool cam::Camera::next ( cv::Mat & frame,
uint32_t & frame_num ) const

Retrieves the next frame.

Parameters
[out]frameAn output parameter for the frame. All data will be overwritten so you do not need to worry about the passed-in Mat having the correct size or format.
[out]frame_numAn output parameter for the frame number.
Returns
true on success, false if some error occurs.

◆ next() [2/2]

bool cam::Camera::next ( cv::Mat & frame,
uint32_t & frame_num,
robot::types::datatime_t & frame_time ) const

Retrives the next frame.

Parameters
[out]frameAn output parameter for the frame. All data will be overwritten so you do not need to worry about the passed-in Mat having the correct size or format.
[out]frame_numAn output parameter for the frame number.
[out]frame_timeAn output parameter for the time at which the frame was captured. Note that this is not the same as the current time.
Returns
true on success, false if some error occurs.

◆ open() [1/2]

bool cam::Camera::open ( int camera_id,
CameraParams intrinsic_params = CameraParams(),
cv::Mat extrinsic_params = cv::Mat() )

Opens a Camera that is not already open.

Will open the camera at the given camera ID and use the given intrinsic and extrinsic parameters, similar to the constructor.

Returns
true if opening the camera succeeds, and false if not.

◆ open() [2/2]

bool cam::Camera::open ( std::string filename,
CameraParams intrinsic_params = CameraParams(),
cv::Mat extrinsic_params = cv::Mat() )

Opens a Camera that is not already open.

Will open the given file for input and use the given intrinsic and extrinsic parameters, similar to the constructor.

Returns
true if opening the camera succeeds, and false if not.

◆ openFromConfigFile()

bool cam::Camera::openFromConfigFile ( std::string filename)

Opens the camera using the given configuration file.

Parameters
filenameThe path to the configuration file to open and read. Configuration file should be formatted as described in Camera Configuration.
Exceptions
invalid_camera_configIf the configuration is invalid for any reason.
std::invalid_argumentIf the configuration file does not exist.

◆ setDescription()

void cam::Camera::setDescription ( std::string new_description)

Updates the description of the camera to the given description.

Parameters
new_descriptionThe new description for the camera.

◆ setName()

void cam::Camera::setName ( std::string new_name)

Updates the name of the camera to the given name.

Parameters
new_nameThe new name for the camera.

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