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 }
ros::Publisher
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
main
int main(int argc, char **argv)
Definition: image_test.cpp:5
ros::NodeHandle::ok
bool ok() const
ros::Duration::sleep
bool sleep() const
ROS_INFO
#define ROS_INFO(...)
ros::Duration
ros::NodeHandle
ros::Time::now
static Time now()


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Sat Jun 1 2024 02:31:53