Skip to content

Commit

Permalink
fix: update initialization of rerun::DepthImage and rerun::Image
Browse files Browse the repository at this point in the history
Signed-off-by: ktro2828 <[email protected]>
  • Loading branch information
ktro2828 committed Aug 20, 2024
1 parent 8a9ca6b commit 67c9032
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
9 changes: 4 additions & 5 deletions awviz_plugin/src/image/compressed_image_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <opencv2/opencv.hpp>

#include <cstdint>
#include <iostream>

namespace awviz_plugin
Expand All @@ -43,17 +44,15 @@ void CompressedImageDisplay::log_message(sensor_msgs::msg::CompressedImage::Cons
cv::cvtColor(img, img, cv::COLOR_BGR2RGB);

stream_->log(
entity_path.value(), rerun::Image(tensor_shape(img), rerun::TensorBuffer::u8(img)));
entity_path.value(), rerun::Image::from_rgb24(img, rerun::WidthHeight(img.cols, img.rows)));
} else {
auto img = cv::imdecode(cv::Mat(msg->data), cv::IMREAD_COLOR);
cv::Mat depth;
img.convertTo(depth, CV_32FC1);

stream_->log(
entity_path.value(), rerun::DepthImage(
{static_cast<size_t>(depth.rows), static_cast<size_t>(depth.cols)},
rerun::TensorBuffer::f32(depth))
.with_meter(1.0));
entity_path.value(),
rerun::DepthImage(depth.data, rerun::WidthHeight(depth.cols, depth.rows)).with_meter(1.0));
}
}
} // namespace awviz_plugin
Expand Down
14 changes: 5 additions & 9 deletions awviz_plugin/src/image/image_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,19 @@ void ImageDisplay::log_message(sensor_msgs::msg::Image::ConstSharedPtr msg)
if (msg->encoding == "16UC1") {
auto img = cv_bridge::toCvCopy(msg)->image;
stream_->log(
entity_path.value(), rerun::DepthImage(
{static_cast<size_t>(img.rows), static_cast<size_t>(img.cols)},
rerun::TensorBuffer::u16(img))
.with_meter(1000));
entity_path.value(),
rerun::DepthImage(img.data, rerun::WidthHeight(img.cols, img.rows)).with_meter(1000));
} else if (msg->encoding == "32FC1") {
auto img = cv_bridge::toCvCopy(msg)->image;

stream_->log(
entity_path.value(), rerun::DepthImage(
{static_cast<size_t>(img.rows), static_cast<size_t>(img.cols)},
rerun::TensorBuffer::f32(img))
.with_meter(1.0));
entity_path.value(),
rerun::DepthImage(img.data, rerun::WidthHeight(img.cols, img.rows)).with_meter(1.0));
} else {
auto img = cv_bridge::toCvCopy(msg, "rgb8")->image;

stream_->log(
entity_path.value(), rerun::Image(tensor_shape(img), rerun::TensorBuffer::u8(img)));
entity_path.value(), rerun::Image::from_rgb24(img, rerun::WidthHeight(img.cols, img.rows)));
}
}
} // namespace awviz_plugin
Expand Down

0 comments on commit 67c9032

Please sign in to comment.