Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I solved it. The solution is to add a shared_ptr to TimeSynchronizer without boost::bind()

class Controller
{
    public:    
        /* Contructor
        */ 
        Controller() 
        {
            img_subscriber.subscribe(node, "processor/image", 1);
            int_subscriber.subscribe(node, "camera/integer", 1); 
            cv::namedWindow("view");
            sync.reset(new message_filters::TimeSynchronizer<sensor_msgs::Image, imagineer::Number>(img_subscriber, int_subscriber, 10));
            service_client = node.serviceClient<imagineer::ImageAck>("ImageAck");
            sync->registerCallback(&Controller::callback, this);   
        }

        void callback(const sensor_msgs::ImageConstPtr& image, const imagineer::Number& digit)
        {

            try
            {
                cv::imshow("view", cv_bridge::toCvCopy(image)->image);
                cv::waitKey(30);
                imagineer::ImageAck ack_service;
                add_to_list(digit, image);
                ROS_INFO("Int and image are saved");
               // send_image(image, ack_service);
               // ROS_INFO("Image sent");
            }
            catch (cv_bridge::Exception& e)
            {
                ROS_ERROR("Error: %s", e.what());
            }
        }

        private:
            ros::NodeHandle node;
            ros::ServiceClient service_client;
            std::vector<NumberAndPicture> storage;
            message_filters::Subscriber<sensor_msgs::Image> img_subscriber; 
            message_filters::Subscriber<imagineer::Number> int_subscriber;
            boost::shared_ptr<message_filters::TimeSynchronizer<sensor_msgs::Image, imagineer::Number>> sync;
};