Skip to content

Commit 677751f

Browse files
authored
Merge pull request #30 from christian-rauch/colour_channel_fix
fix colour channel order for point cloud
2 parents 702f123 + 1b576d0 commit 677751f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/gazebo_ros_realsense.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,19 @@ bool GazeboRosRealsense::FillPointCloudHelper(sensor_msgs::PointCloud2 &point_cl
163163
if (this->image_msg_.data.size() == rows_arg * cols_arg * 3)
164164
{
165165
// color
166-
iter_rgb[0] = image_src[i * 3 + j * cols_arg * 3 + 0];
167-
iter_rgb[1] = image_src[i * 3 + j * cols_arg * 3 + 1];
168-
iter_rgb[2] = image_src[i * 3 + j * cols_arg * 3 + 2];
166+
if (this->image_msg_.encoding == sensor_msgs::image_encodings::RGB8) {
167+
iter_rgb[2] = image_src[i * 3 + j * cols_arg * 3 + 0];
168+
iter_rgb[1] = image_src[i * 3 + j * cols_arg * 3 + 1];
169+
iter_rgb[0] = image_src[i * 3 + j * cols_arg * 3 + 2];
170+
}
171+
else if (this->image_msg_.encoding == sensor_msgs::image_encodings::BGR8) {
172+
iter_rgb[0] = image_src[i * 3 + j * cols_arg * 3 + 0];
173+
iter_rgb[1] = image_src[i * 3 + j * cols_arg * 3 + 1];
174+
iter_rgb[2] = image_src[i * 3 + j * cols_arg * 3 + 2];
175+
}
176+
else {
177+
throw std::runtime_error("unsupported colour encoding: " + this->image_msg_.encoding);
178+
}
169179
}
170180
else if (this->image_msg_.data.size() == rows_arg * cols_arg)
171181
{

0 commit comments

Comments
 (0)