rgbd
full_screen_viewer.cpp
Go to the documentation of this file.
1 #include <ros/console.h>
2 #include <ros/duration.h>
3 #include <ros/init.h>
4 #include <ros/master.h>
5 #include <ros/names.h>
6 #include <ros/node_handle.h>
7 #include <ros/rate.h>
8 #include <ros/time.h>
9 
10 #include "rgbd/client.h"
11 #include "rgbd/view.h"
12 #include <opencv2/highgui/highgui.hpp>
13 
14 int main(int argc, char **argv)
15 {
16  ros::init(argc, argv, "rgbd_viewer");
17  ros::NodeHandle nh_private("~");
18 
19  float rate = 30;
20  nh_private.getParam("rate", rate);
21 
22  rgbd::Client client;
23  client.initialize(ros::names::resolve("rgbd"));
24 
25  const std::string window_name = "RGBD_VIEW";
26  cv::namedWindow(window_name, cv::WINDOW_NORMAL);
27  cv::setWindowProperty(window_name, cv::WND_PROP_FULLSCREEN, cv::WINDOW_FULLSCREEN);
28 
29  bool PAUSE = false;
30 
31  cv::Mat canvas;
32 
33  rgbd::Image image;
34 
35  ros::WallTime last_master_check = ros::WallTime::now();
36 
37  ros::Rate r(rate);
38  while (ros::ok())
39  {
40  if (ros::WallTime::now() >= last_master_check + ros::WallDuration(1))
41  {
42  last_master_check = ros::WallTime::now();
43  if (!ros::master::check())
44  {
45  ROS_FATAL("Lost connection to master");
46  return 1;
47  }
48  }
49  if (!PAUSE && client.nextImage(image))
50  {
51  // Show rgb image
52  if (image.getRGBImage().data)
53  canvas = image.getRGBImage();
54  }
55 
56  if (PAUSE)
57  cv::putText(canvas, "PAUSED", cv::Point(10, canvas.rows - 25), cv::FONT_HERSHEY_COMPLEX_SMALL, 1, cv::Scalar(255, 255, 255), 1);
58 
59  cv::imshow(window_name, canvas);
60 
61  int i_key = cv::waitKey(3);
62  if (i_key >= 0)
63  {
64  char key = static_cast<char>(i_key);
65 
66  if (key == ' ')
67  PAUSE = !PAUSE;
68  else if (key == 'q')
69  break;
70  }
71 
72  r.sleep();
73  }
74 
75  return 0;
76 }
std::string
PAUSE
bool PAUSE
Definition: multitool.cpp:17
rgbd::Image
Definition: image.h:43
rgbd::Client::initialize
bool initialize(const std::string &server_name, float timeout=5.0)
Initialize the client.
Definition: client.cpp:34
main
int main(int argc, char **argv)
Definition: full_screen_viewer.cpp:14
rgbd::Image::getRGBImage
const cv::Mat & getRGBImage() const
Get the RGB color image.
Definition: image.h:78
view.h
rgbd::Client
Client which uses the interfaces of ClientRGBD and ClientSHM.
Definition: client.h:29
client.h
rgbd::Client::nextImage
bool nextImage(Image &image)
Get a new Image. If no new image has been received since the last call, no image will be written and ...
Definition: client.cpp:76