diff --git a/image_publisher/include/image_publisher/image_publisher.hpp b/image_publisher/include/image_publisher/image_publisher.hpp index 6c22b0199..758ad82d9 100644 --- a/image_publisher/include/image_publisher/image_publisher.hpp +++ b/image_publisher/include/image_publisher/image_publisher.hpp @@ -67,6 +67,7 @@ class ImagePublisher : public rclcpp::Node std::string filename_; bool flip_horizontal_; bool flip_vertical_; + bool image_flipped_; bool retry_; // If enabled will retry loading image from the filename_ int timeout_; // Time after which retrying starts diff --git a/image_publisher/src/image_publisher.cpp b/image_publisher/src/image_publisher.cpp index 1f8068de4..25d6e5b52 100644 --- a/image_publisher/src/image_publisher.cpp +++ b/image_publisher/src/image_publisher.cpp @@ -144,9 +144,11 @@ void ImagePublisher::doWork() if (!cap_.read(image_)) { cap_.set(cv::CAP_PROP_POS_FRAMES, 0); } + image_flipped_ = false; } - if (flip_image_) { + if (flip_image_ && !image_flipped_) { cv::flip(image_, image_, flip_value_); + image_flipped_ = true; } sensor_msgs::msg::Image::SharedPtr out_img = @@ -213,6 +215,7 @@ void ImagePublisher::onInit() } else { flip_image_ = false; } + image_flipped_ = false; // Image newly read, needs to be flipped camera_info_.width = image_.cols; camera_info_.height = image_.rows;