Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image_publisher: Fix image, constantly flipping when static image is published (backport #986) #988

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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

Expand Down
5 changes: 4 additions & 1 deletion image_publisher/src/image_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,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 =
Expand Down Expand Up @@ -206,6 +208,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;
Expand Down
Loading