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

Definition of a ROI publisher with c++

asked 2013-04-22 22:36:28 -0500

Bison gravatar image

updated 2013-04-24 00:25:45 -0500

Philip gravatar image

Hi communitiy, I'm currently using the procrob functional face detection package, which is completely written in c++. In one of the functions I am getting a rectangle that includes a recognized face. The variables that I get are: x- and y-postition of the upper left corner pixel and the width and height of the rectangle. I want to publish these information as a RegionOfInterest. But I don't know how to define the ROI-Publisher in c++. Does anyone else know?

Thank you for your help, Greetings from Germany, Bison

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-04-23 02:56:13 -0500

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;
}
edit flag offensive delete link more

Comments

Thank you very much. That's exactly what i was looking for. I did the tutorial but I am really not into c++ yet. Greetings from Germany

Bison gravatar image Bison  ( 2013-04-23 03:10:38 -0500 )edit
0

answered 2013-04-22 22:54:15 -0500

dornhege gravatar image

You mean this message?

That looks to have exactly the values that you are getting, so you can just put them in there.

edit flag offensive delete link more

Comments

Yes, that's exactly the type of message I want to publish. My problem is that I'm not very familiar with c++. I just don't know how to write the publisher for that type of message.

Bison gravatar image Bison  ( 2013-04-23 01:05:23 -0500 )edit

Ah, there's the problem. If @Jeremy Zoss's answer fixes your problem click the checkmark to accept it.

dornhege gravatar image dornhege  ( 2013-04-23 07:35:15 -0500 )edit

Done. Thank you for your answers.

Bison gravatar image Bison  ( 2013-04-23 19:43:57 -0500 )edit

Question Tools

Stats

Asked: 2013-04-22 22:36:28 -0500

Seen: 932 times

Last updated: Apr 23 '13