Robotics StackExchange | Archived questions

Use CVbridge to save ROS messages into Mat variable

I trying to use CVbridge to save ROS messages into mat variables, such that other function function can use that Mat variable to perform Vision related stuff..

But every time i use the cvbridge::CvImagePtr cvptr->image

I get an assertion error saying:

main: /usr/include/boost/smart_ptr/shared_ptr.hpp:653: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = const cv_bridge::CvImage; typename boost::detail::sp_member_access<T>::type = const cv_bridge::CvImage*]: Assertion `px != 0' failed.
Aborted (core dumped)

My callback function for conversion Ros messages to OpenCV images looks like this.

void ImageConverter::imageDetect(const sensor_msgs::ImageConstPtr& msg)
  {
    try
    {
      cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
    }
    catch (cv_bridge::Exception& e)
    {
      ROS_ERROR("cv_bridge exception: %s", e.what());
      return;
    }
        cout << "I am out" << endl;
        frame = cv_ptr->image;

  }

the frame is of type mat..

How do i make so other function, within the class , can use this Mat?..

Asked by 215 on 2015-03-19 16:14:05 UTC

Comments

Please post some more code! where is your cv_ptr defined?

Asked by Wolf on 2015-03-20 08:39:41 UTC

Could you solve this problem? I am currently facing the same error. :/

Asked by soulfutterer on 2015-05-30 08:21:21 UTC

Answers