conversion CV_32FC1 to CV_16UC1
I want to convert a depth message from CV_32FC1 to CV_16UC1. According to docs CvImage should do this..yes?
const sensor_msgs::ImageConstPtr& msgD
cv::Mat cv_frame = cv_bridge::toCvCopy(msgD)->image;
sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), sensor_msgs::image_encodings::MONO16, cv_frame).toImageMsg();
I tried using the code above but get the error:
[ERROR] [1508617331.856469965]: Error loading image: OGRE EXCEPTION(2:InvalidParametersException): Stream size does not match calculated image size in Image::loadRawData at /build/ogre-1.9-mqY1wq/ogre-1.9-1.9.0+dfsg1/OgreMain/src/OgreImage.cpp (line 283)
This error only appears when trying to display the image in rviz
This works in that it does not get an error but displays garbage in rviz. If the above and below look the same ...bcause they are I now get an image ...though garbage after reboot of machine.
cv::Mat cv_frame32 = cv_bridge::toCvCopy(msgD)->image;
sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), sensor_msgs::image_encodings::MONO16, cv_frame32).toImageMsg();
pub.publish(msg);
Finally if I do:
if (cv_ptrD->image.type() == CV_32FC1) { cv::Mat cv_frame32 = cv_bridge::toCvCopy(msgD,sensor_msgs::image_encodings::MONO16)->image;
I get the error:
what(): [32FC1] is not a color format. but [mono16] is. The conversion does not make sense