ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Use cv_bridge and make sure to set the encoding to 16-bit
For example
cv_bridge::CvImage img16;
// copy raw image into img16.image
img16.encoding = sensor_msgs::image_encodings::MONO16;
// img16.header
image_pub.publish(img16);
Just remember to convert it into a 8-bit before displaying it.
image_callback(const snesor_msgs::ImageConstPtr& img)
{
cv_bridge::CvImagePtr cv_ptr;
cv_ptr = cv_bridge::toCvCopy(img, sensor_msgs::image_encodings::MONO16);
cv::Mat img8(HEIGHT, WIDTH, CV_8UC1);
cv_ptr->image.convertTo(img8, CV_8UC1);
cv::imshow("8-bit Mono", img8);
cv::waitKey(1);
}