Skip to content

Commit

Permalink
Add return-by-value versions of cv2ros and ros2cv
Browse files Browse the repository at this point in the history
  • Loading branch information
raultapia committed Apr 16, 2024
1 parent f9767c3 commit e701323
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions include/rush/ros-cv-bridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ inline void cv2ros(const cv::Mat &cv, sensor_msgs::Image &ros, const std_msgs::H
cv_bridge::CvImage(header, Encoding::get(cv), cv).toImageMsg(ros);
}

/**
* @brief Converts an OpenCV Mat to a ROS Image message.
* @param cv The input OpenCV Mat.
* @param header The header for the ROS Image message.
* @return The output ROS Image message.
*/
inline sensor_msgs::Image cv2ros(const cv::Mat &cv, const std_msgs::Header &header = std_msgs::Header()) {
sensor_msgs::Image ros;
cv_bridge::CvImage(header, Encoding::get(cv), cv).toImageMsg(ros);
return ros;
}

/**
* @brief Converts a ROS Image message to an OpenCV Mat.
* @param ros The input ROS Image message.
Expand All @@ -65,6 +77,16 @@ inline void ros2cv(const sensor_msgs::Image &ros, cv::Mat &cv) {
(cv_ptr->image).copyTo(cv);
}

/**
* @brief Converts a ROS Image message to an OpenCV Mat.
* @param ros The input ROS Image message.
* @return The output OpenCV Mat.
*/
inline cv::Mat ros2cv(const sensor_msgs::Image &ros) {
const cv_bridge::CvImagePtr cv_ptr = cv_bridge::toCvCopy(ros, ros.encoding);
return (cv_ptr->image);
}

/**
* @brief This class extends ros::Publisher to directly publish OpenCV matrices.
*/
Expand Down

0 comments on commit e701323

Please sign in to comment.