rgbd
analyser.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 
13 int main(int argc, char **argv)
14 {
15  if (argc <= 1)
16  {
17  std::cout << "Please provide rgbd topic" << std::endl;
18  return 1;
19  }
20 
21  ros::init(argc, argv, "rgbd_viewer");
22  ros::NodeHandle nh_private("~");
23 
24  float rate = 30;
25  nh_private.getParam("rate", rate);
26 
27  rgbd::Client client;
28  client.initialize(ros::names::resolve(argv[1]));
29 
30  rgbd::Image image;
31 
32  ros::WallTime last_master_check = ros::WallTime::now();
33 
34  ros::Rate r(rate);
35  while (ros::ok())
36  {
37  if (ros::WallTime::now() >= last_master_check + ros::WallDuration(1))
38  {
39  last_master_check = ros::WallTime::now();
40  if (!ros::master::check())
41  {
42  ROS_FATAL("Lost connection to master");
43  return 1;
44  }
45  }
46  if (!client.nextImage(image))
47  {
48  r.sleep();
49  continue;
50  }
51 
52  const cv::Mat& depth = image.getDepthImage();
53  const cv::Mat& rgb = image.getRGBImage();
54 
55  std::cout << "------------------------------------------------" << std::endl;
56  std::cout << "time: " << ros::Time(image.getTimestamp()) << std::endl;
57 
58  if (depth.data)
59  {
60  rgbd::View view(image, depth.cols);
61  const geo::DepthCamera& cam_model = view.getRasterizer();
62 
63  std::cout << "depth:" << std::endl;
64  std::cout << " camera model:" << std::endl;
65  std::cout << " fx, fy = " << cam_model.getFocalLengthX() << ", " << cam_model.getFocalLengthY() << std::endl;
66  std::cout << " cx, cy = " << cam_model.getOpticalCenterX() << ", " << cam_model.getOpticalCenterY() << std::endl;
67  std::cout << " Tx, Ty = " << cam_model.getOpticalTranslationX() << ", " << cam_model.getOpticalTranslationY() << std::endl;
68  std::cout << " size = " << depth.cols << " x " << depth.rows << std::endl;
69  }
70  else
71  {
72  std::cout << "depth: NO INFO" << std::endl;
73  }
74 
75  if (rgb.data)
76  {
77  std::cout << "rgb:" << std::endl;
78  std::cout << " size = " << rgb.cols << " x " << rgb.rows << std::endl;
79  }
80  else
81  {
82  std::cout << "rgb: NO INFO" << std::endl;
83  }
84 
85  r.sleep();
86  }
87 
88  return 0;
89 }
geo::DepthCamera::getOpticalCenterY
double getOpticalCenterY() const
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
geo::DepthCamera::getOpticalTranslationX
double getOpticalTranslationX() const
std::cout
rgbd::Image
Definition: image.h:43
rgbd::View::getRasterizer
const geo::DepthCamera & getRasterizer() const
Definition: view.h:54
main
int main(int argc, char **argv)
Definition: analyser.cpp:13
rgbd::Client::initialize
bool initialize(const std::string &server_name, float timeout=5.0)
Initialize the client.
Definition: client.cpp:34
geo::DepthCamera::getFocalLengthX
double getFocalLengthX() const
rgbd::Image::getRGBImage
const cv::Mat & getRGBImage() const
Get the RGB color image.
Definition: image.h:78
geo::DepthCamera::getOpticalTranslationY
double getOpticalTranslationY() const
std::endl
T endl(T... args)
geo::DepthCamera::getFocalLengthY
double getFocalLengthY() const
view.h
geo::DepthCamera
rgbd::Client
Client which uses the interfaces of ClientRGBD and ClientSHM.
Definition: client.h:29
rgbd::View
Definition: view.h:11
geo::DepthCamera::getOpticalCenterX
double getOpticalCenterX() const
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