ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

conversion CV_32FC1 to CV_16UC1

asked 2017-10-21 15:34:55 -0600

rnunziata gravatar image

updated 2017-10-21 16:54:07 -0600

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
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-10-21 17:06:02 -0600

rnunziata gravatar image

This works....I am not sure how to get ride of the second endcoding reference or even if it is necessary. Will update this post if I find out.

  cv::Mat cv_frame32 = cv_bridge::toCvCopy(msgD,sensor_msgs::image_encodings::TYPE_16UC1)->image;         
  sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), sensor_msgs::image_encodings::TYPE_16UC1, cv_frame32).toImageMsg();
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-10-21 15:34:55 -0600

Seen: 2,418 times

Last updated: Oct 21 '17