Skip to content

Commit 1c6ff87

Browse files
committed
Fix compile error caused by rosidl_buffer introduction
Compiling this in rolling results in the following error: /build/bag2_to_image-release-release-rolling-bag2_to_image-0.1.1-1/src/bag2_to_image.cpp: In constructor 'bag2_to_image::Bag2ToImageNode::Bag2ToImageNode(const rclcpp::NodeOptions&)': /build/bag2_to_image-release-release-rolling-bag2_to_image-0.1.1-1/src/bag2_to_image.cpp:165:52: error: no matching function for call to 'cv::Mat::Mat(sensor_msgs::msg::CompressedImage_<std::allocator<void> >::_data_type&)' 165 | auto mat = cv::imdecode(cv::Mat(image->data), imdecode_flag_); | ^ These are caused by ros2/rosidl#941 and followup PRs, which change the type of `uint8[]` message fields from `std::vector<uint8_t>` to `rosidl::Buffer<uint8_t>`. To maintain the previous functionality, explicit typecasting is needed. This causes invocation of the conversion operator [1], which returns a reference to the underlying std::vector. [1]: https://github.com/ros2/rosidl/blob/7c4e0f90f2979c16c906d65058fc7966360f52e1/rosidl_buffer/include/rosidl_buffer/buffer.hpp#L420 Signed-off-by: Michal Sojka <michal.sojka@cvut.cz>
1 parent b535bd2 commit 1c6ff87

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/bag2_to_image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Bag2ToImageNode::Bag2ToImageNode(const rclcpp::NodeOptions & options)
162162
#endif
163163
deserializer_->deserialize(serialized_message, type_support, ros_message);
164164
try {
165-
auto mat = cv::imdecode(cv::Mat(image->data), imdecode_flag_);
165+
auto mat = cv::imdecode(cv::Mat(static_cast<std::vector<uint8_t>&>(image->data)), imdecode_flag_);
166166

167167
const size_t split_pos = image->format.find(';');
168168
std::string image_encoding = image->format.substr(0, split_pos);

0 commit comments

Comments
 (0)