Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
|
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 (robot::types::CameraID camera_id, CameraParams intrinsic_params=CameraParams(), cv::Mat extrinsic_params=cv::Mat()) |
Opens a Camera that is not already open. | |
Camera (robot::types::CameraID 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. | |
std::string | getGSTPipe (robot::types::CameraID camera_id) |
Creates a GStreamer Pipeline using the configuration file associated with the given camera ID. | |
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. | |
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.
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.
cam::Camera::Camera | ( | robot::types::CameraID | 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.
filename | The 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. |
name | The name of the camera. This should ideally be unique, but isn't enforced at this time. |
description | An optional description of the camera. |
cam::Camera::Camera | ( | const Camera & | other | ) |
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.
std::string cam::Camera::getGSTPipe | ( | robot::types::CameraID | camera_id | ) |
Creates a GStreamer Pipeline using the configuration file associated with the given camera ID.
camera_id | The camera ID to construct a pipeline of. |
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.
last_frame_num | The frame number that was returned when retrieving a frame. |
Retrieves the next frame.
[out] | frame | An 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_num | An output parameter for the frame number. |
bool cam::Camera::next | ( | cv::Mat & | frame, |
uint32_t & | frame_num, | ||
robot::types::datatime_t & | frame_time ) const |
Retrives the next frame.
[out] | frame | An 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_num | An output parameter for the frame number. |
[out] | frame_time | An output parameter for the time at which the frame was captured. Note that this is not the same as the current time. |
bool cam::Camera::open | ( | robot::types::CameraID | 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.
void cam::Camera::setDescription | ( | std::string | new_description | ) |
Updates the description of the camera to the given description.
new_description | The new description for the camera. |
void cam::Camera::setName | ( | std::string | new_name | ) |
Updates the name of the camera to the given name.
new_name | The new name for the camera. |