Use CVbridge to save ROS messages into Mat variable

asked 2015-03-19 16:14:05 -0500

215 gravatar image

updated 2015-03-19 16:19:07 -0500

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 cv_bridge::CvImagePtr cv_ptr->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?..

edit retag flag offensive close merge delete

Comments

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

Wolf gravatar imageWolf ( 2015-03-20 08:39:41 -0500 )edit

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

soulfutterer gravatar imagesoulfutterer ( 2015-05-30 08:21:21 -0500 )edit