Skip to content

Commit

Permalink
image_publisher: Fix image, constantly flipping when static image is …
Browse files Browse the repository at this point in the history
…published (backport #986) (#987)

Continuation of
#984.

When publishing video stream from a camera, the image was flipped
correctly. Yet for a static image, which was loaded once, the flip
function was applied every time `ImagePublisher::doWork()` was called,
resulting in the published image being flipped back and forth all the
time.

This PR should be straightforward to port it to `Humble`, `Iron` and
`Jazzy`.<hr>This is an automatic backport of pull request #986 done by
[Mergify](https://mergify.com).

Co-authored-by: Krzysztof Wojciechowski <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
3 people authored Jun 10, 2024
1 parent 5250a7d commit 9b12654
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ImagePublisher : public rclcpp::Node
double field_of_view_;
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 @@ -152,9 +152,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 @@ -221,6 +223,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

0 comments on commit 9b12654

Please sign in to comment.