@@ -331,6 +331,8 @@ GridmapUpdaterNode::topic_callback_info(sensor_msgs::msg::CameraInfo::UniquePtr
331331 camera_model_ = std::make_shared<image_geometry::PinholeCameraModel>();
332332 camera_model_->fromCameraInfo (*msg);
333333
334+ camera_info_received_ = true ;
335+
334336 subscription_info_ = nullptr ;
335337}
336338
@@ -349,7 +351,11 @@ GridmapUpdaterNode::image_callback(sensor_msgs::msg::Image::UniquePtr msg)
349351 }
350352 else if (msg->encoding == sensor_msgs::image_encodings::MONO8)
351353 {
352- image_rgb_ptr = cv_bridge::toCvCopy (*msg, sensor_msgs::image_encodings::MONO8);
354+ image_rgb_ptr = cv_bridge::toCvCopy (*msg, sensor_msgs::image_encodings::MONO8);
355+ }
356+ else if (msg->encoding == sensor_msgs::image_encodings::BGRA8)
357+ {
358+ image_rgb_ptr = cv_bridge::toCvCopy (*msg, sensor_msgs::image_encodings::BGRA8);
353359 }
354360 else
355361 {
@@ -368,6 +374,13 @@ GridmapUpdaterNode::image_callback(sensor_msgs::msg::Image::UniquePtr msg)
368374std::tuple<float , int , int >
369375GridmapUpdaterNode::get_point_color (pcl::PointXYZ point)
370376{
377+
378+ if (!camera_info_received_)
379+ {
380+ RCLCPP_ERROR (get_logger (), " Error: Camera info not received" );
381+ return {-1.0 , -1.0 , -1.0 };
382+ }
383+
371384 cv::Mat world_point_fromCamera = (cv::Mat_<double >(3 , 1 ) << point.x , point.y , point.z );
372385
373386 cv::Mat intrinsic_matrix = cv::Mat (camera_model_->intrinsicMatrix ());
@@ -382,7 +395,7 @@ GridmapUpdaterNode::get_point_color(pcl::PointXYZ point)
382395 if (image_rgb_raw_.type () == CV_8UC3)
383396 {
384397 cv::Vec3b color = image_rgb_raw_.at <cv::Vec3b>(int (point_y), int (point_x));
385- Eigen::Vector3i color_eigen (color[2 ], color[1 ], color[0 ]);
398+ Eigen::Vector3i color_eigen (color[0 ], color[1 ], color[2 ]);
386399 float color_value;
387400 grid_map::colorVectorToValue (color_eigen, color_value);
388401 return {color_value, point_x, point_y};
@@ -392,6 +405,14 @@ GridmapUpdaterNode::get_point_color(pcl::PointXYZ point)
392405 float color_value = image_rgb_raw_.at <uint8_t >(int (point_y), int (point_x));
393406 return {color_value, point_x, point_y};
394407 }
408+ else if (image_rgb_raw_.type () == CV_8UC4)
409+ {
410+ cv::Vec4b color = image_rgb_raw_.at <cv::Vec4b>(int (point_y), int (point_x));
411+ Eigen::Vector3i color_eigen (color[2 ], color[1 ], color[0 ]);
412+ float color_value;
413+ grid_map::colorVectorToValue (color_eigen, color_value);
414+ return {color_value, point_x, point_y};
415+ }
395416 else
396417 {
397418 RCLCPP_ERROR (get_logger (), " Error: Image encoding not supported" );
0 commit comments