0
$\begingroup$

Rosanswers logo

#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 ?


Originally posted by ROSkinect on ROS Answers with karma: 751 on 2014-05-14

Post score: 0

$\endgroup$

2 Answers 2

1
$\begingroup$

Rosanswers logo

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

There is a lot of questions about it here already


Originally posted by Maya with karma: 1172 on 2014-05-14

This answer was NOT ACCEPTED on the original site

Post score: 2

$\endgroup$
0
$\begingroup$

Rosanswers logo

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


Originally posted by makokal with karma: 1295 on 2014-05-14

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.