We may get:
cv_bridge exception: [16UC1] is not a color format. but [mono8] is. The conversion does not make sense
const sensor_msgs::ImageConstPtr & msg
if (msg->encoding == "16UC1"){
sensor_msgs::Image img;
img.header = msg->header;
img.height = msg->height;
img.width = msg->width;
img.is_bigendian = msg->is_bigendian;
img.step = msg->step;
img.data = msg->data;
img.encoding = "mono16";
cv_ptr = cv_bridge::toCvCopy(img, enc::MONO8);
}
Being data the Image message from a subscription callback...
bridge = CvBridge()
data.encoding = "mono16"
cvImage = bridge.imgmsg_to_cv2(data, "mono8")
In Cpp I have to use
sensor_msgs::image_encodings::MONO8
not enc:: ?!
But my image is just black ... :(
Also what I do not understand why do we need MONO8 and not MONO16?