rgbd
test_client_templ.h
Go to the documentation of this file.
1 #ifndef TEST_CLIENT_TEMPL_H_
2 #define TEST_CLIENT_TEMPL_H_
3 
4 #include <opencv2/highgui/highgui.hpp>
5 
6 #include <ros/console.h>
7 #include <ros/duration.h>
8 #include <ros/init.h>
9 #include <ros/master.h>
10 #include <ros/names.h>
11 #include <ros/node_handle.h>
12 #include <ros/rate.h>
13 #include <ros/time.h>
14 
15 #include "rgbd/image.h"
16 
17 #include <string>
18 
19 
20 void usage()
21 {
22  std::cout << "Usage: rgbd_test_client_TYPE [--headless] [--help]" << std::endl;
23 }
24 
38 template<class T>
39 int main_templ(int argc, char **argv)
40 {
41  ros::init(argc, argv, "rgbd_transport_test_client");
42 
43  bool headless = false;
44  std::string arg;
45  for (int i=1; i<argc; ++i)
46  {
47  arg = argv[i];
48  if (arg == "--headless")
49  {
50  headless = true;
51  ROS_INFO("Running in headless mode");
52  }
53  else if(arg == "--help")
54  {
55  usage();
56  return 1;
57  }
58  else
59  {
60  ROS_WARN_STREAM("Incorrect argument: '" << arg);
61  }
62  }
63 
64  ros::NodeHandle nh_private("~");
65 
66  float rate = 30;
67  nh_private.getParam("rate", rate);
68 
69  T client;
70  if (!client.initialize(ros::names::resolve("test")))
71  {
72  ROS_FATAL("Could not initialize the client");
73  return 1;
74  }
75 
76  rgbd::Image image;
77 
78  ros::WallTime last_master_check = ros::WallTime::now();
79 
80  ros::Rate r(rate);
81  while (ros::ok())
82  {
83  if (ros::WallTime::now() >= last_master_check + ros::WallDuration(1))
84  {
85  last_master_check = ros::WallTime::now();
86  if (!ros::master::check())
87  {
88  ROS_FATAL("Lost connection to master");
89  return 1;
90  }
91  }
92  if (client.nextImage(image))
93  {
94  std::cout << "Image: t = " << std::fixed << std::setprecision(12) << image.getTimestamp() << ", frame = " << image.getFrameId() << std::endl;
95 
96  if (!headless)
97  {
98  cv::imshow("rgb", image.getRGBImage());
99  cv::imshow("depth", image.getDepthImage() / 8);
100  cv::waitKey(3);
101  }
102  }
103  r.sleep();
104  }
105 
106  if (!headless)
107  {
108  cv::destroyAllWindows();
109  }
110 
111  return 0;
112 }
113 
114 #endif // TEST_CLIENT_TEMPL_H_
std::setprecision
T setprecision(T... args)
std::string
rgbd::Image::getDepthImage
const cv::Mat & getDepthImage() const
Get the depth image.
Definition: image.h:72
rgbd::Image::getTimestamp
double getTimestamp() const
Get the timestamp.
Definition: image.h:90
std::cout
rgbd::Image
Definition: image.h:43
usage
void usage()
Definition: test_client_templ.h:20
image.h
main_templ
int main_templ(int argc, char **argv)
Definition: test_client_templ.h:39
rgbd::Image::getRGBImage
const cv::Mat & getRGBImage() const
Get the RGB color image.
Definition: image.h:78
std::endl
T endl(T... args)
rgbd::Image::getFrameId
const std::string & getFrameId() const
Get the frame_id.
Definition: image.h:84
std::fixed
T fixed(T... args)
string