From cc369ca8488cf9dd0b6286d1c351658eae555237 Mon Sep 17 00:00:00 2001
From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com>
Date: Wed, 11 Dec 2024 09:50:15 +0100
Subject: [PATCH] `image_view_node`: support bayer images (backport #1046)
(#1058)
so far bayer images always failed with an error:
```
[ERROR] [..] [image_view_node]: Unable to convert 'bayer_rggb8' image for display: 'cv_bridge.cvtColorForDisplay() does not have an output encoding that is color or mono, and has is bit in depth'
```
the `stereo_view_node` on the other hand already supports bayer images,
however it always forcibly converts them to monochrome, even if they are
colour images.
for now, this adds the same logic for the single-image viewer and thus
only partially resolves #1045.
This is an automatic backport of pull
request #1046 done by [Mergify](https://mergify.com).
Co-authored-by: Ralph Ursprung <39383228+rursprung@users.noreply.github.com>
---
image_view/src/image_view_node.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/image_view/src/image_view_node.cpp b/image_view/src/image_view_node.cpp
index 951eedd9c..c3dc1a388 100644
--- a/image_view/src/image_view_node.cpp
+++ b/image_view/src/image_view_node.cpp
@@ -216,6 +216,11 @@ void ImageViewNode::imageCb(const sensor_msgs::msg::Image::ConstSharedPtr & msg)
std::string encoding = msg->encoding.empty() ? "bgr8" : msg->encoding;
+ // May want to view raw bayer data
+ if (encoding.find("bayer") != std::string::npos) {
+ encoding = "mono8";
+ }
+
queued_image_.set(
cv_bridge::cvtColorForDisplay(
cv_bridge::toCvShare(msg), encoding, options));