Robotics StackExchange | Archived questions

Convert an array of sensor_msgs::Image to an array of cv::Mat

Hello,

I am getting an array of images through a ros service, sensor_msgs/Image[] masks

Is there a cleaner way of converting this array of ros images to an array of cv mat? The cv_bridge::toCvShare requires an ImageConstPtr

currently I have it working with a copy constructor and iterate through the array:

sensor_msgs::Image mask = masks[0];

sensormsgs::ImageConstPtr maskconstptr( new sensormsgs::Image( mask) );

maskptr = cvbridge::toCvShare(maskconstptr, sensormsgs::imageencodings::TYPE_8UC1);

cv::Mat image = mask_ptr->image;

I get the following error if I use:

sensormsgs::ImageConstPtr maskconstptr = boost::sharedptr(masks[0]):

error: no matching function for call to ‘boost::sharedptr<sensormsgs::Imagestd::allocator<void > >::sharedptr(gnu_cxx::alloctraits<std::allocator<sensormsgs::Imagestd::allocator<void > > >::valuetype&)

Thanks

Asked by ray30031 on 2018-11-30 13:21:56 UTC

Comments

Hi, did you find a solution to this? Thanks

Asked by ap on 2020-01-14 04:11:38 UTC

Answers