Ask Your Question

Simple question in C++ function pointer

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

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;
        cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);

    catch (cv_bridge::Exception& e)
        ROS_ERROR("cv_bridge exception: %s", e.what());
    cv::imshow("OpenCV viewer uEye", cv_ptr->image);


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");

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

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

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

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

makokal gravatar image

Use the boost bind utilities for that. Here is a nice tutorial on how to go about that

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


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

Seen: 327 times

Last updated: May 14 '14