1 #include "ed_sensor_integration/FitModel.h"
2 #include "ed_sensor_integration/GetModels.h"
3 #include "ed_sensor_integration/GetSnapshots.h"
6 #include <ros/node_handle.h>
7 #include <ros/service_client.h>
9 #include <opencv2/highgui/highgui.hpp>
10 #include <opencv2/imgproc/imgproc.hpp>
12 #include "ed_sensor_integration/GUIAction.h"
58 void DrawModels(cv::Mat& img,
unsigned int i_start);
66 if (event == CV_EVENT_LBUTTONDOWN)
118 img.setTo(cv::Vec3b(20, 20, 20));
121 double width = img.cols;
122 for(
unsigned int i = i_start; i <
models_.size(); ++i)
126 const cv::Mat& model_img =
models_[i].image;
136 cv::Rect rect(cv::Point(
BORDER_SIZE, y), cv::Size(ratio * model_img.cols, ratio * model_img.rows));
137 cv::Mat roi = img(rect);
139 cv::resize(model_img, roi, rect.size());
143 cv::rectangle(img, rect, cv::Scalar(50, 50, 255), 3);
149 cv::rectangle(img, cv::Point(5, 0), cv::Point(width - 5,
BUTTON_SIZE), cv::Scalar(20, 20, 100), 2, 1);
150 cv::rectangle(img, cv::Point(5, img.rows -
BUTTON_SIZE), cv::Point(width - 5, img.rows), cv::Scalar(20, 20, 100), 2, 1);
158 cv::rectangle(img, cv::Point(0, 0), cv::Point(
BUTTON_SIZE, img.rows), cv::Scalar(20, 20, 100), 2, 1);
159 cv::rectangle(img, cv::Point(img.cols -
BUTTON_SIZE, 0), cv::Point(img.cols, img.rows), cv::Scalar(20, 20, 100), 2, 1);
165 const cv::Mat& snapshot = it->second;
168 (
double)(img.rows - 2 *
BORDER_SIZE) / snapshot.rows);
171 cv::Size(ratio * snapshot.cols, ratio * snapshot.rows));
173 cv::Mat roi = img(rect);
174 cv::resize(snapshot, roi, rect.size());
186 void cbGUIAction(
const ed_sensor_integration::GUIAction::ConstPtr& msg)
188 if (msg->action ==
"switch_snapshot")
193 else if (msg->action ==
"fit_model")
197 double click_x_ratio = atof(msg->params[2].c_str());
198 double click_y_ratio = atof(msg->params[3].c_str());
206 int main(
int argc,
char **argv)
208 ros::init(argc, argv,
"ed_fitter_gui");
212 ros::ServiceClient cl_get_snapshots = nh.serviceClient<ed_sensor_integration::GetSnapshots>(
"ed/gui/get_snapshots");
213 ros::ServiceClient cl_get_models = nh.serviceClient<ed_sensor_integration::GetModels>(
"ed/gui/get_models");
214 cl_fit_model_ = nh.serviceClient<ed_sensor_integration::FitModel>(
"ed/gui/fit_model");
216 ros::Subscriber sub_gui_actions_= nh.subscribe<ed_sensor_integration::GUIAction>(
"ed/gui/viz_action", 1,
cbGUIAction);
218 cv::Mat canvas(480, 840, CV_8UC3, cv::Scalar(20, 20, 20));
220 cv::namedWindow(
"Fitter GUI", 1);
224 model_view =
View(canvas, cv::Rect(cv::Point(640, 0), cv::Size(200, 480)));
226 ros::Time t_last_update(0);
230 ros::Time time = ros::Time::now();
232 if (time - t_last_update > ros::Duration(1.0))
236 ed_sensor_integration::GetModels srv;
237 if (cl_get_models.call(srv))
239 std::cout <<
"received: " << srv.response.model_images.size() <<
" models" <<
std::endl;
241 models_.resize(srv.response.model_names.size());
242 for(
unsigned int i = 0; i < srv.response.model_names.size(); ++i)
245 m.
image = cv::imdecode(srv.response.model_images[i].data, CV_LOAD_IMAGE_UNCHANGED);
246 m.
name = srv.response.model_names[i];
260 ed_sensor_integration::GetSnapshots srv;
263 if (cl_get_snapshots.call(srv))
265 std::cout <<
"received: " << srv.response.images.size() <<
" new images" <<
std::endl;
267 for(
unsigned int i = 0; i < srv.response.images.size(); ++i)
269 cv::Mat
image = cv::imdecode(srv.response.images[i].data, CV_LOAD_IMAGE_UNCHANGED);
279 ROS_ERROR(
"Could not call service");
282 t_last_update = time;
285 cv::imshow(
"Fitter GUI", canvas);