@@ -101,14 +101,11 @@ class ImageNodelet : public nodelet::Nodelet
101101 boost::format filename_format_;
102102 int count_;
103103
104- ros::WallTimer gui_timer_;
105-
106104 virtual void onInit ();
107105
108106 void imageCb (const sensor_msgs::ImageConstPtr& msg);
109107
110108 static void mouseCb (int event, int x, int y, int flags, void * param);
111- static void guiCb (const ros::WallTimerEvent&);
112109
113110 void windowThread ();
114111
@@ -165,12 +162,6 @@ void ImageNodelet::onInit()
165162 local_nh.param (" filename_format" , format_string, std::string (" frame%04i.jpg" ));
166163 filename_format_.parse (format_string);
167164
168- // Since cv::startWindowThread() triggers a crash in cv::waitKey()
169- // if OpenCV is compiled against GTK, we call cv::waitKey() from
170- // the ROS event loop periodically, instead.
171- /* cv::startWindowThread();*/
172- gui_timer_ = local_nh.createWallTimer (ros::WallDuration (0.1 ), ImageNodelet::guiCb);
173-
174165 window_thread_ = boost::thread (&ImageNodelet::windowThread, this );
175166
176167 image_transport::ImageTransport it (nh);
@@ -195,12 +186,6 @@ void ImageNodelet::imageCb(const sensor_msgs::ImageConstPtr& msg)
195186 }
196187}
197188
198- void ImageNodelet::guiCb (const ros::WallTimerEvent&)
199- {
200- // Process pending GUI events and return immediately
201- cv::waitKey (1 );
202- }
203-
204189void ImageNodelet::mouseCb (int event, int x, int y, int flags, void * param)
205190{
206191 ImageNodelet *this_ = reinterpret_cast <ImageNodelet*>(param);
@@ -243,19 +228,29 @@ void ImageNodelet::windowThread()
243228
244229 try
245230 {
246- while (true )
231+ while (ros::ok () )
247232 {
248233 cv::Mat image (queued_image_.pop ());
249234 cv::imshow (window_name_, image);
250- cv::waitKey (1 );
251235 shown_image_.set (image);
236+ cv::waitKey (1 );
237+
238+ if (cv::getWindowProperty (window_name_, 1 ) < 0 )
239+ {
240+ break ;
241+ }
252242 }
253243 }
254244 catch (const boost::thread_interrupted&)
255245 {
256246 }
257247
258248 cv::destroyWindow (window_name_);
249+
250+ if (ros::ok ())
251+ {
252+ ros::shutdown ();
253+ }
259254}
260255
261256} // namespace image_view
0 commit comments