0
$\begingroup$

Rosanswers logo

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 ?


Originally posted by jeanpolochon on ROS Answers with karma: 140 on 2017-07-05

Post score: 0

$\endgroup$

2 Answers 2

1
$\begingroup$

Rosanswers logo

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);
}

Originally posted by jeanpolochon with karma: 140 on 2017-07-05

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

See if some of the other answers to very similar questions are of any help

http://answers.ros.org/question/60182/error-unable-to-convert-32fc1-image-to-bgr8-while-extracting-rbgd-data-from-a-bag/

http://answers.ros.org/question/199642/is-it-possible-to-convert-depth-messages-as-ipl-image-using-cvbridge/

http://answers.ros.org/question/212747/cvbridge-conversion-problem-asus-xtion-depth-image-to-opencv/


Originally posted by lucasw with karma: 8729 on 2017-07-05

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.