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 !!