CV_Bridge | Conversion between Image's ROS data type and opencv data type

Introduction of ros official website

http://wiki.ros.org/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages

There is an error on the official website:

 

The encoding method of the depth map, the official website uses mono16, it is estimated that it is a problem of version update, this encoding method will report an error.

[ERROR] [1525783791.845026210]: Could not convert from '16UC1' to 'mono16'.

 

correct code

namespace enc = sensor_msgs::image_encodings;
void depth_Callback(const sensor_msgs::ImageConstPtr& depth_msg)
{
  try
  {
    cv::imshow("depth_view", cv_bridge::toCvShare(depth_msg, enc::TYPE_16UC1)->image);
    cv::waitKey(10);
  }
  catch (cv_bridge::Exception& e)
  {
    ROS_ERROR("Could not convert from '%s' to 'mono16'.", depth_msg->encoding.c_str());
  }

Use  TYPE_16UC1  !!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325893344&siteId=291194637