subscribe multiple topics using two callbacks and one class then pass the value of one callback to other [closed]

asked 2013-07-31 09:58:03 -0500

fairy gravatar image

updated 2013-08-01 03:49:30 -0500

thebyohazard gravatar image

hello! i m working on a ros integrated with opencv using cvbridge library, i have worked with opencv and ros separately then use cvbridge for integration of both of them, actually i m developing a playing activity with turtlebot, my task is to find ball and then hit the ball towards goaling point, for this purpose i have tracked a circle then found its centre co-ordinates, now i want to retrieve a depth of the circle centre by subscribing it to depth topic so basically i need two topics rgb and depth simultanueosly, i have done multiple topic subscription in ros using two call backs in a single class, both callbacks subscribe to different topic but its working till one callback use rospointer msg and other using opencv data type like iplimage, mat

void imageCb(const sensor_msgs::ImageConstPtr& msg)
{
    sensor_msgs::CvBridge bridge;
    IplImage* img = bridge.imgMsgToCv(msg,"bgr8");
}


void imageCb1(const sensor_msgs::ImageConstPtr& msg1)
{
     cv_bridge::CvImagePtr cv_ptr1;
     try
     {
         cv_ptr1 = cv_bridge::toCvCopy(msg1, enc::TYPE_32FC1);
     }
     catch (cv_bridge::Exception& e)
     {
         ROS_ERROR("cv_bridge exception: %s", e.what());
         return;
     }

     if (cv_ptr1->image.rows > 60 && cv_ptr1->image.cols > 60)
         cv::circle(cv_ptr1->image, cv::Point(50, 50), 10, CV_RGB(255,0,0));

     cv::imshow(WINDOW1, cv_ptr1->image);
     cv::waitKey(3);

     image_pub_1.publish(cv_ptr1->toImageMsg());
}

but when i am trying to use opencv purely in both callbacks by using conversion,

void imageCb1(const sensor_msgs::ImageConstPtr& msg1)
{ 
    sensor_msgs::CvBridge bridge1;
    IplImage* img1 = bridge1.img1MsgToCv(msg1,"TYPE_32FC1");    
    Mat mat(img1);
}

void imageCb(const sensor_msgs::ImageConstPtr& msg)
{
    sensor_msgs::CvBridge bridge;
    IplImage* img1 = bridge.img1MsgToCv(msg1,"bgr8");
}

conflict occur that produces segmentation fault

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2016-04-27 01:58:31.178080