3 #include <ed_sensor_integration/Segment.h>
6 #include <ed_gui_server/GetEntityInfo.h>
7 #include <ed_perception/Classify.h>
9 #include <opencv2/imgproc/imgproc.hpp>
10 #include <opencv2/highgui/highgui.hpp>
18 for(
int y = 0; y < img.rows; ++y)
20 if (img.at<cv::Vec3b>(y, x) != clr)
31 for(
int x = 0; x < img.cols; ++x)
33 if (img.at<cv::Vec3b>(y, x) != clr)
45 for(
int x = 0; x < img.cols; ++x)
54 int x_max = img.cols - 1;
55 for(
int x = x_max; x >= 0; --x)
65 for(
int y = 0; y < img.rows; ++y)
74 int y_max = img.rows - 1;
75 for(
int y = y_max; y >= 0; --y)
84 return cv::Rect(cv::Point(x_min, y_min), cv::Point(x_max, y_max));
91 if ( event == cv::EVENT_LBUTTONDOWN )
95 else if ( event == cv::EVENT_RBUTTONDOWN )
99 else if ( event == cv::EVENT_MBUTTONDOWN )
103 else if ( event == cv::EVENT_MOUSEMOVE )
111 int main(
int argc,
char **argv)
113 ros::init(argc, argv,
"segment_and_show");
115 ros::ServiceClient cl_segment = nh.serviceClient<ed_sensor_integration::Segment>(
"ed/kinect/segment");
116 ros::ServiceClient cl_info = nh.serviceClient<ed_gui_server::GetEntityInfo>(
"ed/gui/get_entity_info");
117 ros::ServiceClient cl_perception = nh.serviceClient<ed_perception::Classify>(
"ed/classify");
119 ed_sensor_integration::Segment srv;
120 srv.request.max_sensor_range = 2.0;
122 if (!cl_segment.call(srv))
132 colors.
push_back(cv::Scalar(255, 255, 0));
133 colors.
push_back(cv::Scalar(0, 255, 255));
134 colors.
push_back(cv::Scalar(255, 0, 255));
138 cv::Mat img_combined;
147 ed_gui_server::GetEntityInfo srv;
148 srv.request.id =
id.
str();
149 srv.request.measurement_image_border = 20;
151 if (!cl_info.call(srv))
157 cv::Mat img = cv::imdecode(srv.response.measurement_image, CV_LOAD_IMAGE_UNCHANGED);
159 if (!img_combined.data)
165 for(
int i = 0; i < img.rows * img.cols; ++i)
167 if (img.at<cv::Vec3b>(i) != cv::Vec3b(0, 0, 0))
169 img_combined.at<cv::Vec3b>(i) = img.at<cv::Vec3b>(i);
177 cv::rectangle(img_combined, roi, colors[i_color], 2);
178 i_color = (i_color + 1) % colors.
size();
182 cv::Mat img_cropped = cv::imdecode(srv.response.measurement_image_unmasked, CV_LOAD_IMAGE_UNCHANGED);
183 cv::imshow(
id.str(), img_cropped);
186 if (!img_combined.data)
193 cv::namedWindow(
"Segmentation", 1);
195 cv::Mat img_combined_resized;
196 cv::resize(img_combined, img_combined_resized, cv::Size(img_combined.cols / 2, img_combined.rows / 2));
198 cv::imshow(
"Segmentation", img_combined_resized);
202 ed_perception::Classify srv_classify;
203 srv_classify.request.ids = ids;
205 if (!cl_perception.call(srv_classify))
211 for(
unsigned int i = 0; i < srv_classify.response.types.size(); ++i)
219 cv::putText(img_combined, type, rois[i].tl(), cv::FONT_HERSHEY_COMPLEX_SMALL, 1, cv::Scalar(255, 255, 255), 1);
226 cv::resize(img_combined, img_combined_resized, cv::Size(img_combined.cols / 2, img_combined.rows / 2));
227 cv::imshow(
"Segmentation", img_combined_resized);