From 7e20ccdf52d75c227f12200ea9f801f65f1e7434 Mon Sep 17 00:00:00 2001 From: SamerKhshiboun Date: Wed, 10 Jan 2024 22:20:55 +0000 Subject: [PATCH] fix occupancy width/height --- realsense2_camera/src/base_realsense_node.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/realsense2_camera/src/base_realsense_node.cpp b/realsense2_camera/src/base_realsense_node.cpp index 28228a2f75..9083406b77 100755 --- a/realsense2_camera/src/base_realsense_node.cpp +++ b/realsense2_camera/src/base_realsense_node.cpp @@ -1003,8 +1003,20 @@ void BaseRealSenseNode::publishFrame( if (f.is()) { auto timage = f.as(); - width = timage.get_width(); - height = timage.get_height(); + if(stream.first == RS2_STREAM_OCCUPANCY) + { + if (!f.supports_frame_metadata(RS2_FRAME_METADATA_OCCUPANCY_GRID_ROWS) || + !f.supports_frame_metadata(RS2_FRAME_METADATA_OCCUPANCY_GRID_COLUMNS)) + throw std::runtime_error("Occupancy rows / columns could not be read from frame metadata"); + + width = static_cast(f.get_frame_metadata(RS2_FRAME_METADATA_OCCUPANCY_GRID_COLUMNS)); + height = static_cast(f.get_frame_metadata(RS2_FRAME_METADATA_OCCUPANCY_GRID_ROWS)); + } + else + { + width = timage.get_width(); + height = timage.get_height(); + } stream_format = timage.get_profile().format(); } else