my_subscriber.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 void imageCallback(const sensor_msgs::ImageConstPtr& msg)
7 {
8  try
9  {
10  cv::imshow("view", cv_bridge::toCvShare(msg, "bgr8")->image);
11  cv::waitKey(10);
12  }
13  catch (cv_bridge::Exception& e)
14  {
15  ROS_ERROR("Could not convert from '%s' to 'bgr8'.", msg->encoding.c_str());
16  }
17 }
18 
19 int main(int argc, char **argv)
20 {
21  ros::init(argc, argv, "image_listener");
22  ros::NodeHandle nh;
23  cv::namedWindow("view");
24  cv::startWindowThread();
26  image_transport::Subscriber sub = it.subscribe("camera/image", 1, imageCallback);
27  ros::spin();
28  cv::destroyWindow("view");
29 }
image_transport::ImageTransport
Advertise and subscribe to image topics.
Definition: image_transport.h:84
image_transport.h
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
main
int main(int argc, char **argv)
Definition: my_subscriber.cpp:19
ros.h
image_transport::Subscriber
Manages a subscription callback on a specific topic that can be interpreted as an Image topic.
Definition: subscriber.h:94
image_transport::ImageTransport::subscribe
Subscriber subscribe(const std::string &base_topic, uint32_t queue_size, const boost::function< void(const sensor_msgs::ImageConstPtr &)> &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
Subscribe to an image topic, version for arbitrary boost::function object.
Definition: image_transport.cpp:114
imageCallback
void imageCallback(const sensor_msgs::ImageConstPtr &msg)
Definition: my_subscriber.cpp:6
ROS_ERROR
#define ROS_ERROR(...)
ros::spin
ROSCPP_DECL void spin()
ros::NodeHandle


image_transport
Author(s): Patrick Mihelich
autogenerated on Sun Nov 14 2021 03:14:21