Add functionality for depth images (16UC1 and 32FC1)#14
Add functionality for depth images (16UC1 and 32FC1)#14mvieth wants to merge 2 commits intoWPI-ARC:masterfrom
Conversation
calderpg
left a comment
There was a problem hiding this comment.
A few minor changes, mostly to keep style of spacing and brackets consistent.
Please consider if other image encodings should handled the same way, for example, mono16 is equivalent to 16UC1, so perhaps both should be handled
| sensor_msgs::Image decompressed; | ||
| cv::Mat decoded = cv::imdecode(compressed.data, CV_LOAD_IMAGE_ANYCOLOR); | ||
| cv::Mat decoded = cv::imdecode(compressed.data, CV_LOAD_IMAGE_UNCHANGED); | ||
| if(decoded.data==NULL) { |
There was a problem hiding this comment.
For style consistency, change to:
if (decoded.data == NULL)
{
| cv::Mat decoded = cv::imdecode(compressed.data, CV_LOAD_IMAGE_UNCHANGED); | ||
| if(decoded.data==NULL) { | ||
| ROS_WARN("Decoding unsuccessful"); | ||
| } else { |
| cv::Mat decoded = cv::imdecode(compressed.data, CV_LOAD_IMAGE_ANYCOLOR); | ||
| cv::Mat decoded = cv::imdecode(compressed.data, CV_LOAD_IMAGE_UNCHANGED); | ||
| if(decoded.data==NULL) { | ||
| ROS_WARN("Decoding unsuccessful"); |
There was a problem hiding this comment.
Since CV->ROS conversion of an image that couldn't be decoded isn't a good idea, this should throw, such as:
throw std::runtime_error("OpenCV image decoding failed");
| encoding_params.push_back(CV_IMWRITE_JPEG_QUALITY); | ||
| encoding_params.push_back(quality); | ||
| bool ret = cv::imencode(".jpg", cv_image, compressed.data, encoding_params); | ||
| bool ret; |
There was a problem hiding this comment.
This should initialize the value, i.e.
bool ret = true;
| ROS_DEBUG("Encoding in tiff format"); | ||
| ret = cv::imencode(".tiff", cv_image, compressed.data, encoding_params); | ||
| // jpeg and png are the only acceptable values for the format field, so it is not set here | ||
| } else { |
| encoding_params.push_back(CV_IMWRITE_JPEG_QUALITY); | ||
| encoding_params.push_back(quality); | ||
| ret = cv::imencode(".jpg", cv_image, compressed.data, encoding_params); | ||
| compressed.format="jpeg"; |
There was a problem hiding this comment.
compressed.format = "jpeg";
| if(image.encoding=="16UC1") { | ||
| ROS_DEBUG("Encoding in png format"); | ||
| ret = cv::imencode(".png", cv_image, compressed.data, encoding_params); | ||
| compressed.format="png"; |
There was a problem hiding this comment.
compressed.format = "png";
| bool ret = cv::imencode(".jpg", cv_image, compressed.data, encoding_params); | ||
| bool ret; | ||
| ROS_DEBUG_STREAM("Image encoding: " << image.encoding); | ||
| if(image.encoding=="16UC1") { |
There was a problem hiding this comment.
if (image.encoding == "16UC1")
{
| ROS_DEBUG("Encoding in png format"); | ||
| ret = cv::imencode(".png", cv_image, compressed.data, encoding_params); | ||
| compressed.format="png"; | ||
| } else if(image.encoding=="32FC1") { |
There was a problem hiding this comment.
}
else if (image.encoding == "32FC1")
{
| } else if(image.encoding=="32FC1") { | ||
| ROS_DEBUG("Encoding in tiff format"); | ||
| ret = cv::imencode(".tiff", cv_image, compressed.data, encoding_params); | ||
| // jpeg and png are the only acceptable values for the format field, so it is not set here |
There was a problem hiding this comment.
I would set compressed.format = "tiff"; here, so that a user looking at raw messages knows what encoding is being used. TIFF-encoded images aren't handled by image_transport already, so setting the format type won't cause any new issues.
|
I made the requested changes. I initialized |
This PR adds functionality to compress images of type 16UC1 and 32FC1, which are common formats for depth images. These types cannot be compressed with jpeg, so png respectively tiff are used.
This PR also adds some debug output.