my_publisher.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
3 #include <opencv2/highgui/highgui.hpp>
4 #include <cv_bridge/cv_bridge.h>
5 
6 int main(int argc, char** argv)
7 {
8  ros::init(argc, argv, "image_publisher");
11  image_transport::Publisher pub = it.advertise("camera/image", 1);
12 
13  cv::Mat image = cv::imread(argv[1], cv::IMREAD_COLOR);
14  sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg();
15 
16  ros::Rate loop_rate(5);
17  while (nh.ok()) {
18  pub.publish(msg);
19  ros::spinOnce();
20  loop_rate.sleep();
21  }
22 }
23 
main
int main(int argc, char **argv)
Definition: my_publisher.cpp:6
image_transport::ImageTransport
Advertise and subscribe to image topics.
Definition: image_transport.h:84
image_transport.h
image_transport::Publisher
Manages advertisements of multiple transport options on an Image topic.
Definition: publisher.h:96
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
ros::spinOnce
ROSCPP_DECL void spinOnce()
image_transport::ImageTransport::advertise
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
Advertise an image topic, simple version.
Definition: image_transport.cpp:100
image_transport::Publisher::publish
void publish(const sensor_msgs::Image &message) const
Publish an image on the topics associated with this Publisher.
Definition: publisher.cpp:188
ros::Rate::sleep
bool sleep()
ros::NodeHandle::ok
bool ok() const
ros::Rate
ros::NodeHandle


image_transport
Author(s): Patrick Mihelich
autogenerated on Sat Jan 20 2024 03:14:50