ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Simple question in C++ function pointer

asked 2014-05-14 22:53:57 -0600

ROSkinect gravatar image
#include <ros/ros.h>
#include <iostream>
#include <image_transport/image_transport.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>

namespace enc = sensor_msgs::image_encodings;

void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{   cv_bridge::CvImagePtr cv_ptr;
    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;
    }
    cv::imshow("OpenCV viewer uEye", cv_ptr->image);
    cv::waitKey(3);

}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "listenerKinectuEye");
    ros::NodeHandle nh;
    image_transport::ImageTransport it(nh);

    image_transport::Subscriber sub = it.subscribe("/camera/image_color", 1, imageCallback);

    ROS_INFO("subscribed to Kinect & uEye topics");
    ros::spin();
}

My question is how can I add a parameter to imageCallback function ? and how to use it in the subscribe (the Syntax) in the main function ?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2014-05-14 23:48:50 -0600

Maya gravatar image

roscpp/Overview lookup the callback type. boost::bind is what you're searching for.

There is a lot of questions about it here already

edit flag offensive delete link more
1

answered 2014-05-14 23:42:05 -0600

makokal gravatar image

Use the boost bind utilities for that. Here is a nice tutorial on how to go about that http://en.highscore.de/cpp/boost/functionobjects.html

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-05-14 22:53:57 -0600

Seen: 680 times

Last updated: May 14 '14