image_show.cpp
Go to the documentation of this file.
00001 
00012 #include <cv_bridge/cv_bridge.h>
00013 #include <image_transport/image_transport.h>
00014 #include <nodelet/nodelet.h>
00015 #include <opencv2/highgui/highgui.hpp>
00016 #include <ros/ros.h>
00017 #include <sensor_msgs/Image.h>
00018 #include <sensor_msgs/image_encodings.h>
00019 
00020 namespace image_show
00021 {
00022 
00023 class ImageShow : public nodelet::Nodelet
00024 {
00025   image_transport::ImageTransport* it_;
00026 
00027   image_transport::Subscriber image_sub_;
00028 
00029   void imageCallback(const sensor_msgs::ImageConstPtr& msg);
00030 
00031   ros::Timer timer_;
00032 
00033 public:
00034   virtual void onInit();
00035 
00036   ImageShow();
00037 };
00038 }  // namespace image_show
00039 
00040 #include <pluginlib/class_list_macros.h>
00041 
00042 PLUGINLIB_EXPORT_CLASS(image_show::ImageShow, nodelet::Nodelet)
00043 
00044 namespace image_show
00045 {
00046 
00047 ImageShow::ImageShow()
00048 {
00049 }
00050 
00051 void ImageShow::onInit()
00052 {
00053   it_ = new image_transport::ImageTransport(getNodeHandle());
00054 
00055   image_sub_ = it_->subscribe("image", 1, &ImageShow::imageCallback, this);
00056 }
00057 
00058 void ImageShow::imageCallback(const sensor_msgs::ImageConstPtr& msg)
00059 {
00060   cv_bridge::CvImagePtr cv_ptr;
00061   try
00062   {
00063     cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
00064   }
00065   catch (cv_bridge::Exception& e)
00066   {
00067     ROS_ERROR("cv_bridge exception: %s", e.what());
00068     return;
00069   }
00070 
00071   // this causes failures
00072   // cv::imshow(ros::this_node::getName(), cv_ptr->image);
00073   // It's possible I can't have two nodelets using imshow in the same nodelet group,
00074   // When I comment out the imshow I get no errors.
00075   // std::cout << getName() << " " << cv_ptr->image.size() << std::endl;
00076   cv::imshow("image_show_" + getName(), cv_ptr->image);
00077   cv::waitKey(5);
00078 }
00079 }  // namespace image_show


screen_grab
Author(s):
autogenerated on Fri Feb 12 2016 00:23:26