apriltag_ros_single_image_client_node.cpp
Go to the documentation of this file.
1 
33 #include <apriltag_ros/AnalyzeSingleImage.h>
34 
35 bool getRosParameter (ros::NodeHandle& pnh, std::string name, double& param)
36 {
37  // Write parameter "name" from ROS Parameter Server into param
38  // Return true if successful, false otherwise
39  if (pnh.hasParam(name.c_str()))
40  {
41  pnh.getParam(name.c_str(), param);
42  ROS_INFO_STREAM("Set camera " << name.c_str() << " = " << param);
43  return true;
44  }
45  else
46  {
47  ROS_ERROR_STREAM("Could not find " << name.c_str() << " parameter!");
48  return false;
49  }
50 }
51 
52 int main(int argc, char **argv)
53 {
54  ros::init(argc, argv, "apriltag_ros_single_image_client");
55 
56  ros::NodeHandle nh;
57  ros::NodeHandle pnh("~");
58 
59  ros::ServiceClient client =
60  nh.serviceClient<apriltag_ros::AnalyzeSingleImage>(
61  "single_image_tag_detection");
62 
63  // Get the request parameters
64  apriltag_ros::AnalyzeSingleImage service;
65  service.request.full_path_where_to_get_image =
66  apriltag_ros::getAprilTagOption<std::string>(
67  pnh, "image_load_path", "");
68  if (service.request.full_path_where_to_get_image.empty())
69  {
70  return 1;
71  }
72  service.request.full_path_where_to_save_image =
73  apriltag_ros::getAprilTagOption<std::string>(
74  pnh, "image_save_path", "");
75  if (service.request.full_path_where_to_save_image.empty())
76  {
77  return 1;
78  }
79 
80  // Replicate sensors_msgs/CameraInfo message (must be up-to-date with the
81  // analyzed image!)
82  service.request.camera_info.distortion_model = "plumb_bob";
83  double fx, fy, cx, cy;
84  if (!getRosParameter(pnh, "fx", fx))
85  return 1;
86  if (!getRosParameter(pnh, "fy", fy))
87  return 1;
88  if (!getRosParameter(pnh, "cx", cx))
89  return 1;
90  if (!getRosParameter(pnh, "cy", cy))
91  return 1;
92  // Intrinsic camera matrix for the raw (distorted) images
93  service.request.camera_info.K[0] = fx;
94  service.request.camera_info.K[2] = cx;
95  service.request.camera_info.K[4] = fy;
96  service.request.camera_info.K[5] = cy;
97  service.request.camera_info.K[8] = 1.0;
98 
99  // Call the service (detect tags in the image specified by the
100  // image_load_path)
101  if (client.call(service))
102  {
103  // use parameter run_quielty=false in order to have the service
104  // print out the tag position and orientation
105  if (service.response.tag_detections.detections.size() == 0)
106  {
107  ROS_WARN_STREAM("No detected tags!");
108  }
109  }
110  else
111  {
112  ROS_ERROR("Failed to call service single_image_tag_detection");
113  return 1;
114  }
115 
116  return 0; // happy ending
117 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
bool getRosParameter(ros::NodeHandle &pnh, std::string name, double &param)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
int main(int argc, char **argv)
#define ROS_WARN_STREAM(args)
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
bool hasParam(const std::string &key) const
#define ROS_ERROR_STREAM(args)
#define ROS_ERROR(...)


apriltag_ros
Author(s): Danylo Malyuta
autogenerated on Sat Apr 10 2021 02:59:26