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

asked 2018-11-30 12:21:56 -0500

ray30031 gravatar image

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];

sensor_msgs::ImageConstPtr mask_const_ptr( new sensor_msgs::Image( mask) );

mask_ptr = cv_bridge::toCvShare(mask_const_ptr, sensor_msgs::image_encodings::TYPE_8UC1);

cv::Mat image = mask_ptr->image;

I get the following error if I use:

sensor_msgs::ImageConstPtr mask_const_ptr = boost::shared_ptr<sensor_msgs::image>(masks[0]):

error: no matching function for call to ‘boost::shared_ptr<sensor_msgs::image_<std::allocator<void> > >::shared_ptr(__gnu_cxx::__alloc_traits<std::allocator<sensor_msgs::image_<std::allocator<void> > > >::value_type&)

Thanks

edit retag flag offensive close merge delete