Changing Tracking Color with Messages

From wikidb
Revision as of 22:35, 28 June 2012 by Edc (Talk | contribs)

Jump to: navigation, search

Instance variables: add color parameters.

class Demo
{
protected:
    ...  

    int min_hue_;
    int max_hue_;
    int min_saturation_;

Constructor: Add a subscriber for /hue_set messages.
Constructor: Init the color parameters.

public:

Demo (ros::NodeHandle & nh):nh_ (nh), it_ (nh_)
{
    ...
    hue_set_sub_ = nh_.subscribe("/hue_set", 1000, 
				 &Demo::hueSetCallback, this);
    min_hue_        =  6;
    max_hue_        = 26;
    min_saturation_ = 96;
}

Callback function: Set new color parameters.

  void hueSetCallback (const geometry_msgs::Point::ConstPtr & hue_set_msg)
  {
    ROS_INFO("*** In hueSetCallback: x: %d   y: %d   z: %d",
	     (int)(hue_set_msg->x), 
             (int)(hue_set_msg->y), 
             (int)(hue_set_msg->z));
    min_hue_        = (int)(hue_set_msg->x);
    max_hue_        = (int)(hue_set_msg->y);
    min_saturation_ = (int)(hue_set_msg->z);
  }
 rostopic pub -1 /hue_set geometry_msgs/Point 95 105 100
eepp@tabor:opencv_edc$ roslaunch launch/test_hue.launch 
... logging to /home/eepp/.ros/log/b9c61d8c-c1a9-11e1-ac1e-0001c005f78e/roslaunch-tabor-3021.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

...

started roslaunch server http://tabor:41133/
15 frames/sec at 1340951431.973778981
15 frames/sec at 1340951432.983857918
15 frames/sec at 1340951433.991471178
15 frames/sec at 1340951434.986086136
[ INFO] [1340951435.242190476]: *** In hueSetCallback: x: 95   y: 105   z: 100
15 frames/sec at 1340951435.991725402