ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
There is a pretty good tutorial describing how to write topic publishers in C++.
Here is a small code sample that should get you started. Note that you'll need to also set up a package, package.xml, and CMakeLists.txt as described here.
#include "ros/ros.h"
#include "sensor_msgs/RegionOfInterest.h"
int main(int argc, char **argv)
{
ros::init(argc, argv, "faceROI");
ros::NodeHandle n;
ros::Publisher pub = n.advertise<sensor_msgs::RegionOfInterest>("faceROI", 1000);
ros::Rate loop_rate(10);
while (ros::ok())
{
<do your code to calculate Face ROI here>
sensor_msgs::RegionOfInterest roi_msg;
roi_msg.x_offset = 10;
roi_msg.y_offset = 10;
roi_msg.height = 200;
roi_msg.width = 100;
pub.publish(roi_msg);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}