SMACC2
|
A potentially owning, potentially non-owning, container of a cv::Mat and ROS header. More...
#include <cv_mat_sensor_msgs_image_type_adapter.hpp>
Public Types | |
using | SensorMsgsImageStorageType = std::variant< std::nullptr_t, std::unique_ptr< sensor_msgs::msg::Image >, std::shared_ptr< sensor_msgs::msg::Image > > |
Public Member Functions | |
IMAGE_TOOLS_PUBLIC | ROSCvMatContainer ()=default |
IMAGE_TOOLS_PUBLIC | ROSCvMatContainer (const ROSCvMatContainer &other) |
IMAGE_TOOLS_PUBLIC ROSCvMatContainer & | operator= (const ROSCvMatContainer &other) |
IMAGE_TOOLS_PUBLIC | ROSCvMatContainer (std::unique_ptr< sensor_msgs::msg::Image > unique_sensor_msgs_image) |
Store an owning pointer to a sensor_msg::msg::Image, and create a cv::Mat that references it. More... | |
IMAGE_TOOLS_PUBLIC | ROSCvMatContainer (std::shared_ptr< sensor_msgs::msg::Image > shared_sensor_msgs_image) |
Store an owning pointer to a sensor_msg::msg::Image, and create a cv::Mat that references it. More... | |
IMAGE_TOOLS_PUBLIC | ROSCvMatContainer (const cv::Mat &mat_frame, const std_msgs::msg::Header &header, bool is_bigendian=is_bigendian_system) |
Shallow copy the given cv::Mat into this class, but do not own the data directly. More... | |
IMAGE_TOOLS_PUBLIC | ROSCvMatContainer (cv::Mat &&mat_frame, const std_msgs::msg::Header &header, bool is_bigendian=is_bigendian_system) |
Move the given cv::Mat into this class. More... | |
IMAGE_TOOLS_PUBLIC | ROSCvMatContainer (const sensor_msgs::msg::Image &sensor_msgs_image) |
Copy the sensor_msgs::msg::Image into this contain and create a cv::Mat that references it. More... | |
IMAGE_TOOLS_PUBLIC bool | is_owning () const |
Return true if this class owns the data the cv_mat references. More... | |
IMAGE_TOOLS_PUBLIC const cv::Mat & | cv_mat () const |
Const access the cv::Mat in this class. More... | |
IMAGE_TOOLS_PUBLIC cv::Mat | cv_mat () |
Get a shallow copy of the cv::Mat that is in this class. More... | |
IMAGE_TOOLS_PUBLIC const std_msgs::msg::Header & | header () const |
Const access the ROS Header. More... | |
IMAGE_TOOLS_PUBLIC std_msgs::msg::Header & | header () |
Access the ROS Header. More... | |
IMAGE_TOOLS_PUBLIC std::shared_ptr< const sensor_msgs::msg::Image > | get_sensor_msgs_msg_image_pointer () const |
Get shared const pointer to the sensor_msgs::msg::Image if available, otherwise nullptr. More... | |
IMAGE_TOOLS_PUBLIC std::unique_ptr< sensor_msgs::msg::Image > | get_sensor_msgs_msg_image_pointer_copy () const |
Get copy as a unique pointer to the sensor_msgs::msg::Image. More... | |
IMAGE_TOOLS_PUBLIC sensor_msgs::msg::Image | get_sensor_msgs_msg_image_copy () const |
Get a copy of the image as a sensor_msgs::msg::Image. More... | |
IMAGE_TOOLS_PUBLIC void | get_sensor_msgs_msg_image_copy (sensor_msgs::msg::Image &sensor_msgs_image) const |
Get a copy of the image as a sensor_msgs::msg::Image. More... | |
IMAGE_TOOLS_PUBLIC bool | is_bigendian () const |
Return true if the data is stored in big endian, otherwise return false. More... | |
Private Attributes | |
std_msgs::msg::Header | header_ |
cv::Mat | frame_ |
SensorMsgsImageStorageType | storage_ |
bool | is_bigendian_ |
Static Private Attributes | |
static constexpr bool | is_bigendian_system = detail::endian::native == detail::endian::big |
A potentially owning, potentially non-owning, container of a cv::Mat and ROS header.
The two main use cases for this are publishing user controlled data, and receiving data from the middleware that may have been a ROS message originally or may have been an cv::Mat originally.
In the first case, publishing user owned data, the user will want to provide their own cv::Mat. The cv::Mat may own the data or it may not, so in the latter case, it is up to the user to ensure the data the cv::Mat points to remains valid as long as the middleware needs it.
In the second case, receiving data from the middleware, the middleware will either give a new ROSCvMatContainer which owns a sensor_msgs::msg::Image or it will give a ROSCvMatContainer that was previously published by the user (in the case of intra-process communication). If the container owns the sensor_msgs::msg::Image, then the cv::Mat will just reference data field of this message, so the container needs to be kept. If the container was published by the user it may or may not own the data and the cv::Mat it contains may or may not own the data.
For these reasons, it is advisable to use cv::Mat::clone() if you intend to copy the cv::Mat and let this container go.
For more details about the ownership behavior of cv::Mat see documentation for these methods of cv::Mat:
Definition at line 94 of file cv_mat_sensor_msgs_image_type_adapter.hpp.
using image_tools::ROSCvMatContainer::SensorMsgsImageStorageType = std::variant< std::nullptr_t, std::unique_ptr<sensor_msgs::msg::Image>, std::shared_ptr<sensor_msgs::msg::Image> > |
Definition at line 99 of file cv_mat_sensor_msgs_image_type_adapter.hpp.
|
default |
|
inlineexplicit |
Definition at line 109 of file cv_mat_sensor_msgs_image_type_adapter.hpp.
References storage_.
|
explicit |
Store an owning pointer to a sensor_msg::msg::Image, and create a cv::Mat that references it.
Definition at line 73 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
|
explicit |
Store an owning pointer to a sensor_msg::msg::Image, and create a cv::Mat that references it.
Definition at line 88 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
image_tools::ROSCvMatContainer::ROSCvMatContainer | ( | const cv::Mat & | mat_frame, |
const std_msgs::msg::Header & | header, | ||
bool | is_bigendian = is_bigendian_system |
||
) |
Shallow copy the given cv::Mat into this class, but do not own the data directly.
Definition at line 100 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
image_tools::ROSCvMatContainer::ROSCvMatContainer | ( | cv::Mat && | mat_frame, |
const std_msgs::msg::Header & | header, | ||
bool | is_bigendian = is_bigendian_system |
||
) |
Move the given cv::Mat into this class.
Definition at line 110 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
|
explicit |
Copy the sensor_msgs::msg::Image into this contain and create a cv::Mat that references it.
Definition at line 120 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
cv::Mat image_tools::ROSCvMatContainer::cv_mat | ( | ) |
Get a shallow copy of the cv::Mat that is in this class.
Note that if you want to let this container go out of scope you should make a deep copy with cv::Mat::clone() beforehand.
Definition at line 138 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
References frame_.
const cv::Mat & image_tools::ROSCvMatContainer::cv_mat | ( | ) | const |
Const access the cv::Mat in this class.
Definition at line 132 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
References frame_.
Referenced by callback(), and rclcpp::TypeAdapter< image_tools::ROSCvMatContainer, sensor_msgs::msg::Image >::convert_to_ros_message().
IMAGE_TOOLS_PUBLIC sensor_msgs::msg::Image image_tools::ROSCvMatContainer::get_sensor_msgs_msg_image_copy | ( | ) | const |
Get a copy of the image as a sensor_msgs::msg::Image.
Referenced by get_sensor_msgs_msg_image_pointer_copy().
void image_tools::ROSCvMatContainer::get_sensor_msgs_msg_image_copy | ( | sensor_msgs::msg::Image & | sensor_msgs_image | ) | const |
Get a copy of the image as a sensor_msgs::msg::Image.
Definition at line 173 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
std::shared_ptr< const sensor_msgs::msg::Image > image_tools::ROSCvMatContainer::get_sensor_msgs_msg_image_pointer | ( | ) | const |
Get shared const pointer to the sensor_msgs::msg::Image if available, otherwise nullptr.
Definition at line 156 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
References storage_.
std::unique_ptr< sensor_msgs::msg::Image > image_tools::ROSCvMatContainer::get_sensor_msgs_msg_image_pointer_copy | ( | ) | const |
Get copy as a unique pointer to the sensor_msgs::msg::Image.
Definition at line 165 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
References get_sensor_msgs_msg_image_copy().
std_msgs::msg::Header & image_tools::ROSCvMatContainer::header | ( | ) |
Access the ROS Header.
Definition at line 150 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
References header_.
const std_msgs::msg::Header & image_tools::ROSCvMatContainer::header | ( | ) | const |
Const access the ROS Header.
Definition at line 144 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
References header_.
Referenced by callback(), and rclcpp::TypeAdapter< image_tools::ROSCvMatContainer, sensor_msgs::msg::Image >::convert_to_ros_message().
bool image_tools::ROSCvMatContainer::is_bigendian | ( | ) | const |
Return true if the data is stored in big endian, otherwise return false.
Definition at line 202 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
References is_bigendian_.
bool image_tools::ROSCvMatContainer::is_owning | ( | ) | const |
Return true if this class owns the data the cv_mat references.
Note that this does not check if the cv::Mat owns its own data, only if this class owns a sensor_msgs::msg::Image that the cv::Mat references.
Definition at line 126 of file cv_mat_sensor_msgs_image_type_adapter.cpp.
References storage_.
|
inline |
Definition at line 121 of file cv_mat_sensor_msgs_image_type_adapter.hpp.
References frame_, header_, is_bigendian_, and storage_.
|
private |
Definition at line 225 of file cv_mat_sensor_msgs_image_type_adapter.hpp.
Referenced by cv_mat(), get_sensor_msgs_msg_image_copy(), and operator=().
|
private |
Definition at line 224 of file cv_mat_sensor_msgs_image_type_adapter.hpp.
Referenced by get_sensor_msgs_msg_image_copy(), header(), and operator=().
|
private |
Definition at line 227 of file cv_mat_sensor_msgs_image_type_adapter.hpp.
Referenced by is_bigendian(), and operator=().
|
staticconstexprprivate |
Definition at line 96 of file cv_mat_sensor_msgs_image_type_adapter.hpp.
|
private |
Definition at line 226 of file cv_mat_sensor_msgs_image_type_adapter.hpp.
Referenced by get_sensor_msgs_msg_image_pointer(), is_owning(), operator=(), and ROSCvMatContainer().