Ask Your Question
0

Conversion from 32FC1 to mono8 using cv_bridge

asked 2017-07-05 04:26:33 -0500

I am trying to use cv_bridge to convert an image from /disp_map/image (32FC1 encoding according to msg->encoding ) to an image usable in opencv with the following code :

void detectionCallback(const sensor_msgs::ImageConstPtr& msg) {
   cv_bridge::CvImagePtr cv_ptr;
   try
   {
     cv_ptr = cv_bridge::toCvCopy(msg, "mono8");
   }
    catch (cv_bridge::Exception& e)
   {
    ROS_ERROR("cv_bridge exception: %s", e.what());
    return;
   }
}

And i get the following error :

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

What's the best solution to solve this ?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-07-05 08:01:06 -0500

updated 2017-07-05 08:01:49 -0500

I manage to make it works using opencv 3 (compiling cv_bridge from sources )

I had to add a few lines of code to convert the image format. This solution is not very efficient but it works. If somebody has a better solution that would be nice !

The code I used :

void detectionCallback(const sensor_msgs::ImageConstPtr& msg)
{
  cv_bridge::CvImageConstPtr cv_ptr;
  try
  {
    cv_ptr = cv_bridge::toCvShare(msg);

  }
  catch (cv_bridge::Exception& e)
  {
    ROS_ERROR("cv_bridge exception: %s", e.what());
    return;
  }

  Mat mono8_img = cv::Mat(cv_ptr->image.size(), CV_8UC1);
  cv::convertScaleAbs(cv_ptr->image, mono8_img, 100, 0.0);
}
edit flag offensive delete link more
1

answered 2017-07-05 07:23:49 -0500

lucasw gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-07-05 04:26:33 -0500

Seen: 2,605 times

Last updated: Jul 05 '17