ros-perception / vision_opencv

Apache License 2.0
536 stars 599 forks source link

how to convert a 32FC1 image message to color formats? #500

Closed thachdo closed 1 year ago

thachdo commented 1 year ago

Hello,

Can we convert a 32FC1 image message to color formats like rbg8 or bgr8?

I'm using the below function

cv_bridge::CvImagePtr cv_ptr;
try
{
  cv_ptr = cv_bridge::toCvCopy(gray_msg, sensor_msgs::image_encodings::BGR8);
}
catch (cv_bridge::Exception& e)
{
  ROS_ERROR("cv_bridge exception: %s", e.what());
  return;
}

and get below error:

[ERROR] [1668071878.177947865]: cv_bridge exception: [32FC1] is not a color format. but [bgr8] is. The conversion does not make sense

Is there a way to convert a gray image message to a color one directly?

ijnek commented 1 year ago

I'm going to assume you want to convert gray image to color image for display purposes. You could use cvtColorForDisplay, and must specify how you want to convert the grayscale to the color format with the CvtColorForDisplayOptions parameter.

https://github.com/ros-perception/vision_opencv/blob/c620dd9210bae632ebb442a63f34e9e0d469c57b/cv_bridge/include/cv_bridge/cv_bridge.hpp#L288-L322