image_test.cpp
Go to the documentation of this file.
1 #include "ros/ros.h"
2 
3 #include "sensor_msgs/Image.h"
4 
5 int main(int argc, char** argv)
6 {
7  ros::init(argc, argv, "image_test");
8 
10 
11  ros::Publisher rgb_pub = n.advertise<sensor_msgs::Image>("red_image", 0);
12 
13  ros::Duration(0.1).sleep();
14 
15  sensor_msgs::Image red_image;
16  red_image.header.frame_id = "/base_link";
17  red_image.header.stamp = ros::Time::now();
18  red_image.height = 100;
19  red_image.width = 100;
20  red_image.encoding = "rgb8";
21  red_image.step = 3 * red_image.height;
22 
23  red_image.data.resize(3 * red_image.height * red_image.width);
24  for (uint32_t i = 0; i < 3 * red_image.height * red_image.width; ++i)
25  {
26  if (i % 3 == 0)
27  {
28  red_image.data[i] = 255;
29  }
30  else
31  {
32  red_image.data[i] = 0;
33  }
34  }
35 
36  int i = 0;
37  while (n.ok())
38  {
39  ROS_INFO("Publishing");
40 
41  rgb_pub.publish(red_image);
42 
43  ++i;
44 
45  ros::Duration(1.0).sleep();
46  }
47 }
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void publish(const boost::shared_ptr< M > &message) const
#define ROS_INFO(...)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int main(int argc, char **argv)
Definition: image_test.cpp:5
static Time now()
bool sleep() const
bool ok() const


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:24