rgbd
test_server_templ.h
Go to the documentation of this file.
1 #ifndef TEST_SERVER_TEMPL_H_
2 #define TEST_SERVER_TEMPL_H_
3 
4 #include <image_geometry/pinhole_camera_model.h>
5 
6 #include "rgbd/image.h"
7 
8 #include <ros/console.h>
9 #include <ros/duration.h>
10 #include <ros/init.h>
11 #include <ros/master.h>
12 #include <ros/names.h>
13 #include <ros/node_handle.h>
14 #include <ros/rate.h>
15 #include <ros/time.h>
16 
17 #include <sensor_msgs/CameraInfo.h>
18 #include <sensor_msgs/distortion_models.h>
19 
33 template<class T>
34 int main_templ(int argc, char **argv)
35 {
36  ros::init(argc, argv, "rgbd_transport_test_server");
37  ros::NodeHandle nh_private("~");
38 
39  float rate = 30;
40  nh_private.getParam("rate", rate);
41 
42  T server;
43  server.initialize(ros::names::resolve("test"));
44 
45  ros::Rate r(rate);
46  cv::Mat rgb_image(480, 640, CV_8UC3, cv::Scalar(0,0,255));
47  cv::Mat depth_image(480, 640, CV_32FC1, 5.0);
48  sensor_msgs::CameraInfo cam_info;
49  cam_info.K = {554.2559327880068, 0.0, 320.5,
50  0.0, 554.2559327880068, 240.5,
51  0.0, 0.0, 1.0};
52  cam_info.P = {554.2559327880068, 0.0, 320.5, 0.0,
53  0.0, 554.2559327880068, 240.5, 0.0,
54  0.0, 0.0, 1.0, 0.0};
55  cam_info.distortion_model = sensor_msgs::distortion_models::PLUMB_BOB;
56  cam_info.width = 640;
57  cam_info.height = 480;
58  image_geometry::PinholeCameraModel cam_model;
59  cam_model.fromCameraInfo(cam_info);
60 
61  rgbd::Image image(rgb_image, depth_image, cam_model, "test_frame_id", ros::Time::now().toSec());
62 
63  ros::WallTime last_master_check = ros::WallTime::now();
64 
65  int x = 0;
66  while (ros::ok())
67  {
68  if (ros::WallTime::now() >= last_master_check + ros::WallDuration(1))
69  {
70  last_master_check = ros::WallTime::now();
71  if (!ros::master::check())
72  {
73  ROS_FATAL("Lost connection to master");
74  return 1;
75  }
76  }
77  cv::line(rgb_image, cv::Point(x, 0), cv::Point(x, rgb_image.rows - 1), cv::Scalar(0,0,255));
78  cv::line(depth_image, cv::Point(x, 0), cv::Point(x, depth_image.rows - 1), 5.0);
79  x = (x + 10) % rgb_image.cols;
80  cv::line(rgb_image, cv::Point(x, 0), cv::Point(x, rgb_image.rows - 1), cv::Scalar(255, 0, 0));
81  cv::line(depth_image, cv::Point(x, 0), cv::Point(x, depth_image.rows - 1), 1.0);
82 
83  image.setRGBImage(rgb_image);
84  image.setDepthImage(depth_image);
85  image.setTimestamp(ros::Time::now().toSec());
86 
87  server.send(image);
88 
89  r.sleep();
90  }
91 
92  return 0;
93 }
94 
95 
96 #endif // TEST_SERVER_TEMPL_H_
rgb_image
cv::Mat rgb_image
Definition: record_to_video.cpp:24
rgbd::Image::setDepthImage
void setDepthImage(const cv::Mat &depth_image)
Set the depth image.
Definition: image.h:105
rgbd::Image::setRGBImage
void setRGBImage(const cv::Mat &rgb_image)
Set the BGR color image.
Definition: image.h:111
rgbd::Image
Definition: image.h:43
rgbd::Image::setTimestamp
void setTimestamp(double timestamp)
Set the timestamp.
Definition: image.h:123
image.h
main_templ
int main_templ(int argc, char **argv)
Definition: test_server_templ.h:34