ed
show_gui.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <opencv2/highgui/highgui.hpp>
3 #include <tue_serialization/Binary.h>
4 #include <ed_msgs/RaiseEvent.h>
5 
6 ros::ServiceClient client;
7 
9 
10 void imageCallback(const tue_serialization::Binary::ConstPtr& msg)
11 {
12  cv::Mat image = cv::imdecode(msg->data, cv::IMREAD_UNCHANGED);
13  cv::imshow("map", image);
14  cv::waitKey(3);
15 }
16 
17 void mouseCallback(int event, int x, int y, int /*flags*/, void* /*ptr*/)
18 {
19  if (event == cv::EVENT_LBUTTONDOWN)
20  {
21  ed_msgs::RaiseEvent srv_ev;
22  srv_ev.request.name = "click";
23  srv_ev.request.param_names.push_back("x");
24  srv_ev.request.param_names.push_back("y");
25 
26  std::stringstream x_str;
27  x_str << x;
28  std::stringstream y_str;
29  y_str << y;
30 
31  srv_ev.request.param_values.push_back(x_str.str());
32  srv_ev.request.param_values.push_back(y_str.str());
33 
34  srv_ev.request.param_names.push_back("type");
35  srv_ev.request.param_values.push_back(click_type);
36 
37  if (client.call(srv_ev))
38  {
39  std::cout << "Response from server: " << srv_ev.response.msg << std::endl;
40  }
41  else
42  {
43  std::cout << "Calling raise event failed" << std::endl;
44  }
45  }
46 }
47 
48 int main(int argc, char **argv)
49 {
50  ros::init(argc, argv, "ed_gui");
51 
52  ros::NodeHandle nh;
53  ros::Subscriber sub_image = nh.subscribe("/ed/gui/map_image", 1, imageCallback);
54  client = nh.serviceClient<ed_msgs::RaiseEvent>("/ed/gui/raise_event");
55 
56  click_type = "navigate";
57  if (argc >= 2)
58  {
59  click_type = argv[1];
60  }
61 
62 
63  cv::namedWindow("map", 1);
64 
65  cv::setMouseCallback("map", mouseCallback);
66 
67 
68  ros::Rate r(30);
69  while(ros::ok())
70  {
71  ros::spinOnce();
72  r.sleep();
73  }
74 
75  return 0;
76 }
mouseCallback
void mouseCallback(int event, int x, int y, int, void *)
Definition: show_gui.cpp:17
std::string
std::stringstream
imageCallback
void imageCallback(const tue_serialization::Binary::ConstPtr &msg)
Definition: show_gui.cpp:10
click_type
std::string click_type
Definition: show_gui.cpp:8
image
cv::Mat image
Definition: view_model.cpp:42
std::cout
client
ros::ServiceClient client
Definition: show_gui.cpp:6
std::endl
T endl(T... args)
main
int main(int argc, char **argv)
Definition: show_gui.cpp:48
std::stringstream::str
T str(T... args)