39 ImageView2::ImageView2() : marker_topic_(
"image_marker"), filename_format_(
""), count_(0), mode_(MODE_RECTANGLE), times_(100), window_initialized_(false),space_(10)
49 std::string camera_info = nh.
resolveName(
"camera_info");
51 std::string format_string;
52 std::string transport;
67 local_nh.
param(
"window_name",
window_name_, std::string(
"image_view2 [")+camera+std::string(
"]"));
70 local_nh.
param(
"image_transport", transport, std::string(
"raw"));
74 local_nh.
param(
"filename_format", format_string, std::string(
"frame%04i.jpg"));
79 local_nh.
param(
"resize_scale_x", xx, 1.0);
80 local_nh.
param(
"resize_scale_y", yy, 1.0);
83 std::string interaction_mode;
84 local_nh.
param(
"interaction_mode", interaction_mode, std::string(
"rectangle"));
90 font_ = cv::FONT_HERSHEY_DUPLEX;
117 srv_ = boost::make_shared <dynamic_reconfigure::Server<Config> >(local_nh);
118 dynamic_reconfigure::Server<Config>::CallbackType
f =
120 srv_->setCallback(f);
141 space_ = config.grid_space;
149 boost::const_pointer_cast<image_view2::ImageMarker2>(marker)->lifetime = (
ros::Time::now() -
ros::Time(0)) + marker->lifetime;
164 std::string frame_id,
ros::Time& acquisition_time,
165 std::map<std::string, int>& tf_fail,
173 acquisition_time, timeout);
175 acquisition_time, transform);
181 if ( tf_fail[frame_id] < 5 ) {
182 ROS_ERROR(
"[image_view2] TF exception:\n%s", ex.what());
184 ROS_DEBUG(
"[image_view2] TF exception:\n%s", ex.what());
192 cv::Point2d uv = cv::Point2d(marker->position.x, marker->position.y);
195 CvScalar co =
MsgToRGB(marker->outline_color);
196 for (
int s1 = s0*10; s1 >= s0; s1--) {
197 double m = pow((1.0-((
double)(s1 - s0))/(s0*9)),2);
198 cv::circle(
draw_, uv,
200 CV_RGB(co.val[2] * m,co.val[1] * m,co.val[0] * m),
204 cv::circle(
draw_, uv,
208 if (marker->filled) {
209 cv::circle(
draw_, uv,
218 std::vector<CvScalar>& colors,
219 std::vector<CvScalar>::iterator& col_it)
224 std::vector<CvScalar>::iterator col_it = colors.begin();
225 CvScalar co = (*col_it);
226 for (
int s1 = s0*10; s1 >= s0; s1--) {
227 double m = pow((1.0-((
double)(s1 - s0))/(s0*9)),2);
228 std::vector<geometry_msgs::Point>::const_iterator it = marker->points.begin();
229 std::vector<geometry_msgs::Point>::const_iterator end = marker->points.end();
230 p0 = cv::Point2d(it->x, it->y); it++;
231 for ( ; it!= end; it++ ) {
232 p1 = cv::Point2d(it->x, it->y);
233 cv::line(
draw_, p0, p1,
234 CV_RGB(co.val[2] * m,co.val[1] * m,co.val[0] * m),
237 if(++col_it == colors.end()) col_it = colors.begin();
241 std::vector<geometry_msgs::Point>::const_iterator it = marker->points.begin();
242 std::vector<geometry_msgs::Point>::const_iterator end = marker->points.end();
243 p0 = cv::Point2d(it->x, it->y); it++;
244 for ( ; it!= end; it++ ) {
245 p1 = cv::Point2d(it->x, it->y);
248 if(++col_it == colors.end()) col_it = colors.begin();
254 std::vector<CvScalar>& colors,
255 std::vector<CvScalar>::iterator& col_it)
260 std::vector<CvScalar>::iterator col_it = colors.begin();
261 CvScalar co = (*col_it);
262 for (
int s1 = s0*10; s1 >= s0; s1--) {
263 double m = pow((1.0-((
double)(s1 - s0))/(s0*9)),2);
264 std::vector<geometry_msgs::Point>::const_iterator it = marker->points.begin();
265 std::vector<geometry_msgs::Point>::const_iterator end = marker->points.end();
266 for ( ; it!= end; ) {
267 p0 = cv::Point2d(it->x, it->y); it++;
268 if ( it != end ) p1 = cv::Point2d(it->x, it->y);
269 cv::line(
draw_, p0, p1, CV_RGB(co.val[2] * m,co.val[1] * m,co.val[0] * m), s1);
271 if(++col_it == colors.end()) col_it = colors.begin();
275 std::vector<geometry_msgs::Point>::const_iterator it = marker->points.begin();
276 std::vector<geometry_msgs::Point>::const_iterator end = marker->points.end();
277 for ( ; it!= end; ) {
278 p0 = cv::Point2d(it->x, it->y); it++;
279 if ( it != end ) p1 = cv::Point2d(it->x, it->y);
282 if(++col_it == colors.end()) col_it = colors.begin();
288 std::vector<CvScalar>& colors,
289 std::vector<CvScalar>::iterator& col_it)
294 std::vector<CvScalar>::iterator col_it = colors.begin();
295 CvScalar co = (*col_it);
296 for (
int s1 = s0*10; s1 >= s0; s1--) {
297 double m = pow((1.0-((
double)(s1 - s0))/(s0*9)),2);
298 std::vector<geometry_msgs::Point>::const_iterator it = marker->points.begin();
299 std::vector<geometry_msgs::Point>::const_iterator end = marker->points.end();
300 p0 = cv::Point2d(it->x, it->y); it++;
301 for ( ; it!= end; it++ ) {
302 p1 = cv::Point2d(it->x, it->y);
303 cv::line(
draw_, p0, p1, CV_RGB(co.val[2] * m,co.val[1] * m,co.val[0] * m), s1);
305 if(++col_it == colors.end()) col_it = colors.begin();
307 it = marker->points.begin();
308 p1 = cv::Point2d(it->x, it->y);
309 cv::line(
draw_, p0, p1, CV_RGB(co.val[2] * m,co.val[1] * m,co.val[0] * m), s1);
312 std::vector<geometry_msgs::Point>::const_iterator it = marker->points.begin();
313 std::vector<geometry_msgs::Point>::const_iterator end = marker->points.end();
314 std::vector<cv::Point> points;
316 if (marker->filled) {
317 points.push_back(cv::Point(it->x, it->y));
319 p0 = cv::Point2d(it->x, it->y); it++;
320 for ( ; it!= end; it++ ) {
321 p1 = cv::Point2d(it->x, it->y);
322 if (marker->filled) {
323 points.push_back(cv::Point(it->x, it->y));
327 if(++col_it == colors.end()) col_it = colors.begin();
329 it = marker->points.begin();
330 p1 = cv::Point2d(it->x, it->y);
332 if (marker->filled) {
333 cv::fillConvexPoly(
draw_, points.data(), points.size(),
MsgToRGB(marker->fill_color));
339 std::vector<CvScalar>& colors,
340 std::vector<CvScalar>::iterator& col_it)
342 BOOST_FOREACH(geometry_msgs::Point p, marker->points) {
343 cv::Point2d uv = cv::Point2d(p.x, p.y);
345 int s0 = (marker->scale == 0 ? 3 : marker->scale);
346 CvScalar co = (*col_it);
347 for (
int s1 = s0*2; s1 >= s0; s1--) {
348 double m = pow((1.0-((
double)(s1 - s0))/s0),2);
349 cv::circle(
draw_, uv, s1,
350 CV_RGB(co.val[2] * m,co.val[1] * m,co.val[0] * m),
354 cv::circle(
draw_, uv, (marker->scale == 0 ? 3 : marker->scale) , *col_it, -1);
356 if(++col_it == colors.end()) col_it = colors.begin();
361 std::vector<CvScalar>& colors,
362 std::vector<CvScalar>::iterator& col_it)
364 static std::map<std::string, int> tf_fail;
365 BOOST_FOREACH(std::string frame_id, marker->frames) {
373 cv::Point3d pt_cv(pt.
x(), pt.
y(), pt.
z());
377 static const int RADIUS = 3;
381 cv::Point2d uv0, uv1, uv2;
401 CvScalar c0 = CV_RGB(255,0,0);
402 CvScalar c1 = CV_RGB(0,255,0);
403 CvScalar c2 = CV_RGB(0,0,255);
404 for (
int s1 = s0*10; s1 >= s0; s1--) {
405 double m = pow((1.0-((
double)(s1 - s0))/(s0*9)),2);
406 cv::line(
draw_, uv, uv0,
407 CV_RGB(c0.val[2] * m,c0.val[1] * m,c0.val[0] * m),
409 cv::line(
draw_, uv, uv1,
410 CV_RGB(c1.val[2] * m,c1.val[1] * m,c1.val[0] * m),
412 cv::line(
draw_, uv, uv2,
413 CV_RGB(c2.val[2] * m,c2.val[1] * m,c2.val[0] * m),
417 cv::line(
draw_, uv, uv0, CV_RGB(255,0,0), 2);
418 cv::line(
draw_, uv, uv1, CV_RGB(0,255,0), 2);
419 cv::line(
draw_, uv, uv2, CV_RGB(0,0,255), 2);
425 text_size = cv::getTextSize(frame_id.c_str(),
font_, 1.0, 1.0, &baseline);
426 cv::Point origin = cv::Point(uv.x - text_size.width / 2,
427 uv.y - RADIUS - baseline - 3);
439 return cv::Point(0, 0);
444 std::vector<CvScalar>& colors,
445 std::vector<CvScalar>::iterator& col_it)
449 float scale = marker->scale;
450 if ( scale == 0 ) scale = 1.0;
451 text_size = cv::getTextSize(marker->text.c_str(),
font_,
452 scale, scale, &baseline);
454 if (marker->ratio_scale) {
455 cv::Size a_size = cv::getTextSize(
"A",
font_, 1.0, 1.0, &baseline);
456 int height_size = a_size.height;
457 double desired_size =
last_msg_->height * scale;
458 scale = desired_size / height_size;
463 if (marker->left_up_origin) {
464 if (marker->ratio_scale) {
469 origin = cv::Point(marker->position.x,
474 if (marker->ratio_scale) {
475 cv::Point p =
ratioPoint(marker->position.x, marker->position.y);
476 origin = cv::Point(p.x - text_size.width/2,
480 origin = cv::Point(marker->position.x - text_size.width/2,
481 marker->position.y + baseline+3);
485 if (marker->filled) {
495 std::vector<CvScalar>& colors,
496 std::vector<CvScalar>::iterator& col_it)
498 static std::map<std::string, int> tf_fail;
499 std::string frame_id = marker->points3D.header.frame_id;
510 acquisition_time, timeout);
512 acquisition_time, transform);
517 if ( tf_fail[frame_id] < 5 ) {
518 ROS_ERROR(
"[image_view2] TF exception:\n%s", ex.what());
520 ROS_DEBUG(
"[image_view2] TF exception:\n%s", ex.what());
524 std::vector<geometry_msgs::Point> points2D;
525 BOOST_FOREACH(geometry_msgs::Point p, marker->points3D.points) {
527 geometry_msgs::PointStamped pt_cam, pt_;
529 pt_cam.header.stamp = acquisition_time;
530 pt_cam.point.x = pt.
x();
531 pt_cam.point.y = pt.
y();
532 pt_cam.point.z = pt.
z();
540 geometry_msgs::Point point2D;
543 points2D.push_back(point2D);
546 std::vector<geometry_msgs::Point>::const_iterator it = points2D.begin();
547 std::vector<geometry_msgs::Point>::const_iterator end = points2D.end();
548 p0 = cv::Point2d(it->x, it->y); it++;
549 for ( ; it!= end; it++ ) {
550 p1 = cv::Point2d(it->x, it->y);
553 if(++col_it == colors.end()) col_it = colors.begin();
558 std::vector<CvScalar>& colors,
559 std::vector<CvScalar>::iterator& col_it)
561 static std::map<std::string, int> tf_fail;
562 std::string frame_id = marker->points3D.header.frame_id;
568 std::vector<geometry_msgs::Point> points2D;
569 BOOST_FOREACH(geometry_msgs::Point p, marker->points3D.points) {
571 geometry_msgs::PointStamped pt_cam, pt_;
573 pt_cam.header.stamp = acquisition_time;
574 pt_cam.point.x = pt.
x();
575 pt_cam.point.y = pt.
y();
576 pt_cam.point.z = pt.
z();
584 geometry_msgs::Point point2D;
587 points2D.push_back(point2D);
590 std::vector<geometry_msgs::Point>::const_iterator it = points2D.begin();
591 std::vector<geometry_msgs::Point>::const_iterator end = points2D.end();
592 for ( ; it!= end; ) {
593 p0 = cv::Point2d(it->x, it->y); it++;
594 if ( it != end ) p1 = cv::Point2d(it->x, it->y);
597 if(++col_it == colors.end()) col_it = colors.begin();
602 std::vector<CvScalar>& colors,
603 std::vector<CvScalar>::iterator& col_it)
605 static std::map<std::string, int> tf_fail;
606 std::string frame_id = marker->points3D.header.frame_id;
612 std::vector<geometry_msgs::Point> points2D;
613 BOOST_FOREACH(geometry_msgs::Point p, marker->points3D.points) {
615 geometry_msgs::PointStamped pt_cam, pt_;
617 pt_cam.header.stamp = acquisition_time;
618 pt_cam.point.x = pt.
x();
619 pt_cam.point.y = pt.
y();
620 pt_cam.point.z = pt.
z();
628 geometry_msgs::Point point2D;
631 points2D.push_back(point2D);
634 std::vector<geometry_msgs::Point>::const_iterator it = points2D.begin();
635 std::vector<geometry_msgs::Point>::const_iterator end = points2D.end();
636 std::vector<cv::Point> points;
638 if (marker->filled) {
639 points.push_back(cv::Point(it->x, it->y));
641 p0 = cv::Point2d(it->x, it->y); it++;
642 for ( ; it!= end; it++ ) {
643 p1 = cv::Point2d(it->x, it->y);
644 if (marker->filled) {
645 points.push_back(cv::Point(it->x, it->y));
649 if(++col_it == colors.end()) col_it = colors.begin();
651 it = points2D.begin();
652 p1 = cv::Point2d(it->x, it->y);
654 if (marker->filled) {
655 cv::fillConvexPoly(
draw_, points.data(), points.size(),
MsgToRGB(marker->fill_color));
660 std::vector<CvScalar>& colors,
661 std::vector<CvScalar>::iterator& col_it)
663 static std::map<std::string, int> tf_fail;
664 std::string frame_id = marker->points3D.header.frame_id;
670 BOOST_FOREACH(geometry_msgs::Point p, marker->points3D.points) {
672 geometry_msgs::PointStamped pt_cam, pt_;
674 pt_cam.header.stamp = acquisition_time;
675 pt_cam.point.x = pt.
x();
676 pt_cam.point.y = pt.
y();
677 pt_cam.point.z = pt.
z();
685 cv::circle(
draw_, uv, (marker->scale == 0 ? 3 : marker->scale) , *col_it, -1);
690 std::vector<CvScalar>& colors,
691 std::vector<CvScalar>::iterator& col_it)
693 static std::map<std::string, int> tf_fail;
694 std::string frame_id = marker->position3D.header.frame_id;
701 geometry_msgs::PointStamped pt_cam, pt_;
703 pt_cam.header.stamp = acquisition_time;
704 pt_cam.point.x = pt.
x();
705 pt_cam.point.y = pt.
y();
706 pt_cam.point.z = pt.
z();
711 pin =
tf::Stamped<tf::Point>(
tf::Point(pt_.point.x + marker->position3D.point.x, pt_.point.y + marker->position3D.point.y, pt_.point.z + marker->position3D.point.z), acquisition_time, frame_id);
716 float scale = marker->scale;
717 if ( scale == 0 ) scale = 1.0;
718 text_size = cv::getTextSize(marker->text.c_str(),
font_,
719 scale, scale, &baseline);
720 cv::Point origin = cv::Point(uv.x - text_size.width/2,
722 cv::putText(
draw_, marker->text.c_str(), origin,
font_, scale, CV_RGB(0,255,0),3);
726 std::vector<CvScalar>& colors,
727 std::vector<CvScalar>::iterator& col_it)
729 static std::map<std::string, int> tf_fail;
730 std::string frame_id = marker->pose.header.frame_id;
731 geometry_msgs::PoseStamped pose;
738 acquisition_time, timeout);
740 acquisition_time, marker->pose, frame_id, pose);
745 if ( tf_fail[frame_id] < 5 ) {
746 ROS_ERROR(
"[image_view2] TF exception:\n%s", ex.what());
748 ROS_DEBUG(
"[image_view2] TF exception:\n%s", ex.what());
756 double angle = (marker->arc == 0 ? 360.0 :marker->angle);
759 std::vector< std::vector<cv::Point2i> > ptss;
760 std::vector<cv::Point2i> pts;
762 for (
int i=0; i<N; ++i) {
766 pts.push_back(cv::Point2i((
int)pt.x, (
int)pt.y));
770 cv::polylines(
draw_, ptss, (marker->arc == 0 ?
true :
false),
MsgToRGB(marker->outline_color), (marker->width == 0 ?
DEFAULT_LINE_WIDTH : marker->width));
772 if (marker->filled) {
773 if(marker->arc != 0){
775 pts.push_back(cv::Point2i((
int)pt.x, (
int)pt.y));
790 V_ImageMarkerMessage::iterator new_msg =
marker_queue_.begin();
791 V_ImageMarkerMessage::iterator message_it =
local_queue_.begin();
792 for ( ; message_it <
local_queue_.end(); ++message_it ) {
793 if((*new_msg)->ns == (*message_it)->ns && (*new_msg)->id == (*message_it)->id)
799 if ( (*new_msg)->action == image_view2::ImageMarker2::REMOVE &&
800 (*new_msg)->id == -1 ) {
808 if((*it)->action == image_view2::ImageMarker2::REMOVE ||
820 V_ImageMarkerMessage::iterator message_it =
local_queue_.begin();
821 V_ImageMarkerMessage::iterator message_end =
local_queue_.end();
824 for ( ; message_it != message_end; ++message_it )
826 image_view2::ImageMarker2::ConstPtr& marker = *message_it;
828 ROS_DEBUG_STREAM(
"message type = " << marker->type <<
", id " << marker->id);
831 std::vector<CvScalar> colors;
832 BOOST_FOREACH(std_msgs::ColorRGBA color, marker->outline_colors) {
836 std::vector<CvScalar>::iterator col_it = colors.begin();
839 if( marker->type == image_view2::ImageMarker2::FRAMES ||
840 marker->type == image_view2::ImageMarker2::LINE_STRIP3D ||
841 marker->type == image_view2::ImageMarker2::LINE_LIST3D ||
842 marker->type == image_view2::ImageMarker2::POLYGON3D ||
843 marker->type == image_view2::ImageMarker2::POINTS3D ||
844 marker->type == image_view2::ImageMarker2::TEXT3D ||
845 marker->type == image_view2::ImageMarker2::CIRCLE3D) {
849 ROS_WARN(
"[image_view2] camera_info could not found");
856 switch ( marker->type ) {
857 case image_view2::ImageMarker2::CIRCLE: {
861 case image_view2::ImageMarker2::LINE_STRIP: {
865 case image_view2::ImageMarker2::LINE_LIST: {
869 case image_view2::ImageMarker2::POLYGON: {
873 case image_view2::ImageMarker2::POINTS: {
877 case image_view2::ImageMarker2::FRAMES: {
881 case image_view2::ImageMarker2::TEXT: {
885 case image_view2::ImageMarker2::LINE_STRIP3D: {
889 case image_view2::ImageMarker2::LINE_LIST3D: {
893 case image_view2::ImageMarker2::POLYGON3D: {
897 case image_view2::ImageMarker2::POINTS3D: {
901 case image_view2::ImageMarker2::TEXT3D: {
905 case image_view2::ImageMarker2::CIRCLE3D: {
910 ROS_WARN(
"Undefined Marker type(%d)", marker->type);
928 cv::Point2d from, to;
940 cv::Point2d from, to;
944 cv::line(
draw_, from, to, CV_RGB(255, 0, 0), 8, 8, 0);
949 cv::Point2d from, to;
953 cv::line(
draw_, from, to, CV_RGB(0, 255, 0), 8, 8, 0);
964 CV_RGB(255, 0, 0), 4);
970 CV_RGB(0, 255, 0), 4);
990 CV_RGB(255, 0, 0), 8, 8, 0);
995 CV_RGB(0, 255, 0), 8, 8, 0);
1004 static std::string info_str_1, info_str_2;
1008 double mean = 0, rate = 1.0, std_dev = 0.0, max_delta, min_delta;
1010 std::for_each(
times_.begin(),
times_.end(), (mean += boost::lambda::_1) );
1014 std::for_each(
times_.begin(),
times_.end(), (std_dev += (boost::lambda::_1 - mean)*(boost::lambda::_1 - mean) ) );
1015 std_dev = sqrt(std_dev/n);
1016 min_delta = *std::min_element(
times_.begin(),
times_.end());
1017 max_delta = *std::max_element(
times_.begin(),
times_.end());
1019 std::stringstream f1, f2;
1020 f1.precision(3); f1 << std::fixed;
1021 f2.precision(3); f2 << std::fixed;
1023 f2 <<
"min:" << min_delta <<
"s max: " << max_delta <<
"s std_dev: " << std_dev <<
"s n: " << n;
1024 info_str_1 = f1.str();
1025 info_str_2 = f2.str();
1028 last_time = before_rendering;
1030 if (!info_str_1.empty() && !info_str_2.empty()) {
1031 cv::putText(
image_, info_str_1.c_str(), cv::Point(10,
image_.rows-34), cv::FONT_HERSHEY_SIMPLEX, 0.8, cv::Scalar::all(255), 2);
1032 cv::putText(
image_, info_str_2.c_str(), cv::Point(10,
image_.rows-10), cv::FONT_HERSHEY_SIMPLEX, 0.8, cv::Scalar::all(255), 2);
1053 ROS_WARN(
"no image is available yet");
1086 cv::Mat distort_grid_mask(
draw_.size(), CV_8UC1);
1087 distort_grid_mask.setTo(cv::Scalar(0));
1088 const float K = 341.0;
1089 float R_divier = (1.0/(
draw_.cols/2)), center_x = distort_grid_mask.rows/2, center_y = distort_grid_mask.cols/2;
1090 for(
int degree = -80; degree<=80; degree+=
space_){
1091 double C =
draw_.cols/2.0 * tan(degree * 3.14159265/180);
1092 for(
float theta = -1.57; theta <= 1.57; theta+=0.001){
1093 double sin_phi = C * R_divier / tan(theta);
1094 if (sin_phi > 1.0 || sin_phi < -1.0)
1096 int x1 = K * theta * sqrt(1-sin_phi * sin_phi) + center_x;
1097 int y1 = K * theta * sin_phi + center_y;
1098 int x2 = K * theta * sin_phi + center_x;
1099 int y2 = K * theta * sqrt(1-sin_phi * sin_phi) + center_y;
1100 cv::circle(distort_grid_mask, cvPoint(y1, x1), 2, 1,
grid_thickness_);
1101 cv::circle(distort_grid_mask, cvPoint(y2, x2), 2, 1,
grid_thickness_);
1104 cv::Mat red(
draw_.size(),
draw_.type(), CV_8UC3);
1125 cv::Point2d p0 = cv::Point2d(0,
last_msg_->height/2.0);
1129 cv::Point2d p2 = cv::Point2d(
last_msg_->width/2.0, 0);
1133 for(
int i = 1; i <
div_u_ ;i ++){
1134 cv::Point2d u0 = cv::Point2d(0,
last_msg_->height * i * 1.0 / div_u_);
1135 cv::Point2d u1 = cv::Point2d(
last_msg_->width,
last_msg_->height * i * 1.0 / div_u_);
1136 cv::line(
draw_, u0, u1, CV_RGB(255,0,0), 1);
1139 for(
int i = 1; i <
div_v_ ;i ++){
1140 cv::Point2d v0 = cv::Point2d(
last_msg_->width * i * 1.0 / div_v_, 0);
1141 cv::Point2d v1 = cv::Point2d(
last_msg_->width * i * 1.0 / div_v_,
last_msg_->height);
1142 cv::line(
draw_, v0, v1, CV_RGB(255,0,0), 1);
1149 if (msg->width == 0 && msg->height == 0) {
1153 static int count = 0;
1166 ROS_WARN(
"TF Cleared for old time");
1170 if (msg->encoding.find(
"bayer") != std::string::npos) {
1172 const_cast<uint8_t*>(&msg->data[0]), msg->step);
1177 cv::minMaxIdx(input_image, &min, &max);
1183 ROS_ERROR(
"Unable to convert %s image to bgr8", msg->encoding.c_str());
1216 ROS_DEBUG(
"setRegionWindowPoint(%d, %d)", x, y);
1271 pcl::PointCloud<pcl::PointXY> pcl_cloud;
1276 pcl_cloud.points.push_back(p);
1278 sensor_msgs::PointCloud2::Ptr ros_cloud(
new sensor_msgs::PointCloud2);
1306 cv::Point2d from, to;
1307 if (points.size() > 1) {
1309 for (
size_t i = 1; i < points.size(); i++) {
1311 cv::line(mask, from, to, cv::Scalar(255), 8, 8, 0);
1319 const std_msgs::Header& header)
1330 cv::Mat foreground_mask
1332 cv::Mat background_mask
1339 cv::rectangle(foreground_mask,
rect_fg_, cv::Scalar(255), CV_FILLED);
1340 cv::rectangle(background_mask,
rect_bg_, cv::Scalar(255), CV_FILLED);
1351 const std_msgs::Header& header)
1353 int min_x = image.cols;
1354 int min_y = image.rows;
1357 for (
int j = 0; j < image.rows; j++) {
1358 for (
int i = 0; i < image.cols; i++) {
1359 if (image.at<uchar>(j, i) != 0) {
1360 min_x = std::min(min_x, i);
1361 min_y = std::min(min_y, j);
1362 max_x = std::max(max_x, i);
1363 max_y = std::max(max_y, j);
1367 geometry_msgs::PolygonStamped poly;
1368 poly.header = header;
1369 geometry_msgs::Point32 min_pt, max_pt;
1374 poly.polygon.points.push_back(min_pt);
1375 poly.polygon.points.push_back(max_pt);
1382 geometry_msgs::PolygonStamped ros_line;
1384 geometry_msgs::Point32 ros_start_point, ros_end_point;
1389 ros_line.polygon.points.push_back(ros_start_point);
1390 ros_line.polygon.points.push_back(ros_end_point);
1409 std::cout <<
"PT_1" << Pt_1 << std::endl;
1410 std::cout <<
"Pt" << Pt << std::endl;
1412 geometry_msgs::PointStamped screen_msg;
1415 screen_msg.point.z = 0;
1416 screen_msg.header.stamp =
last_msg_->header.stamp;
1420 geometry_msgs::PolygonStamped screen_msg;
1421 screen_msg.polygon.points.resize(2);
1428 screen_msg.polygon.points[0].x, screen_msg.polygon.points[0].y,
1429 screen_msg.polygon.points[1].x, screen_msg.polygon.points[1].y);
1438 const cv::Point2f& end_point)
1440 double dist_px = cv::norm(cv::Mat(start_point), cv::Mat(end_point));
1441 return dist_px > 3.0;
1511 cv::Point2f Pt(x, y);
1528 geometry_msgs::PointStamped move_point;
1530 move_point.point.x = x;
1531 move_point.point.y = y;
1532 move_point.point.z = 0;
1596 geometry_msgs::PolygonStamped poly;
1599 geometry_msgs::Point32 p;
1603 poly.polygon.points.push_back(p);
1637 case CV_EVENT_MOUSEMOVE: {
1641 case CV_EVENT_LBUTTONDOWN:
1644 case CV_EVENT_LBUTTONUP:
1647 case CV_EVENT_RBUTTONDOWN:
1659 cv::imwrite(filename.c_str(),
image_);
1660 ROS_INFO(
"Saved image %s", filename.c_str());
1663 ROS_WARN(
"Couldn't save image, no data!");
1714 x = std::max(std::min(x, (
int)
last_msg_->width), 0);
1715 y = std::max(std::min(y, (
int)
last_msg_->height), 0);
1749 std_srvs::EmptyRequest& req,
1750 std_srvs::EmptyResponse& res)
1759 std_srvs::EmptyRequest& req,
1760 std_srvs::EmptyResponse& res)
1769 std_srvs::EmptyRequest& req,
1770 std_srvs::EmptyResponse& res)
1779 std_srvs::EmptyRequest& req,
1780 std_srvs::EmptyResponse& res)
1789 std_srvs::EmptyRequest& req,
1790 std_srvs::EmptyResponse& res)
1799 std_srvs::EmptyRequest& req,
1800 std_srvs::EmptyResponse& res)
1809 std_srvs::EmptyRequest& req,
1810 std_srvs::EmptyResponse& res)
1819 image_view2::ChangeModeRequest& req,
1820 image_view2::ChangeModeResponse& res)
1831 if (interaction_mode ==
"rectangle") {
1834 else if (interaction_mode ==
"freeform" ||
1835 interaction_mode ==
"series") {
1838 else if (interaction_mode ==
"grabcut") {
1841 else if (interaction_mode ==
"grabcut_rect") {
1844 else if (interaction_mode ==
"line") {
1847 else if (interaction_mode ==
"poly") {
1850 else if (interaction_mode ==
"none") {
1854 throw std::string(
"Unknown mode");
1859 const image_view2::MouseEvent::ConstPtr& event_msg)
1862 if (event_msg->type == image_view2::MouseEvent::KEY_PRESSED) {
1871 ROS_WARN(
"Image is not yet available");
1874 x = ((float)
last_msg_->width / event_msg->width) * event_msg->x;
1875 y = ((float)
last_msg_->height / event_msg->height) * event_msg->y;
1878 if (event_msg->type == image_view2::MouseEvent::MOUSE_LEFT_UP) {
1882 else if (event_msg->type == image_view2::MouseEvent::MOUSE_LEFT_DOWN) {
1886 else if (event_msg->type == image_view2::MouseEvent::MOUSE_MOVE) {
1890 else if (event_msg->type == image_view2::MouseEvent::MOUSE_RIGHT_DOWN) {
void config_callback(Config &config, uint32_t level)
ros::Publisher point_pub_
Subscriber subscribe(const std::string &base_topic, uint32_t queue_size, const boost::function< void(const sensor_msgs::ImageConstPtr &)> &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
image_transport::Subscriber image_sub_
boost::mutex image_mutex_
cv::Point line_end_point_
void setMode(KEY_MODE mode)
ros::Subscriber info_sub_
cv::Point2f button_up_pos_
void updateLineEndPoint(cv::Point p)
void publish(const boost::shared_ptr< M > &message) const
void publishMonoImage(ros::Publisher &pub, cv::Mat &image, const std_msgs::Header &header)
ros::ServiceServer grabcut_mode_srv_
void updatePolyPoint(cv::Point p)
ros::ServiceServer rectangle_mode_srv_
void updateLinePoint(cv::Point p)
ros::Publisher rectangle_img_pub_
void addPoint(int x, int y)
bool noneModeServiceCallback(std_srvs::EmptyRequest &req, std_srvs::EmptyResponse &res)
cv::Point poly_selecting_point_
std::vector< cv::Point2d > point_fg_array_
bool left_button_clicked_
void drawPolygon(const image_view2::ImageMarker2::ConstPtr &marker, std::vector< CvScalar > &colors, std::vector< CvScalar >::iterator &col_it)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::Publisher background_rect_pub_
sensor_msgs::CameraInfoConstPtr info_msg_
std::string resolveName(const std::string &name, bool remap=true) const
boost::circular_buffer< double > times_
ros::ServiceServer line_mode_srv_
void drawText3D(const image_view2::ImageMarker2::ConstPtr &marker, std::vector< CvScalar > &colors, std::vector< CvScalar >::iterator &col_it)
void resolveLocalMarkerQueue()
std::string marker_topic_
ros::ServiceServer none_mode_srv_
bool seriesModeServiceCallback(std_srvs::EmptyRequest &req, std_srvs::EmptyResponse &res)
void drawFrames(const image_view2::ImageMarker2::ConstPtr &marker, std::vector< CvScalar > &colors, std::vector< CvScalar >::iterator &col_it)
void setRegionWindowPoint(int x, int y)
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
void drawLineStrip(const image_view2::ImageMarker2::ConstPtr &marker, std::vector< CvScalar > &colors, std::vector< CvScalar >::iterator &col_it)
cv::Point line_start_point_
cv::Point getLineStartPoint()
bool isPolySelectingFirstTime()
void drawLineList(const image_view2::ImageMarker2::ConstPtr &marker, std::vector< CvScalar > &colors, std::vector< CvScalar >::iterator &col_it)
ros::ServiceServer change_mode_srv_
void updateRegionWindowSize(int x, int y)
void drawCircle(const image_view2::ImageMarker2::ConstPtr &marker)
TFSIMD_FORCE_INLINE const tfScalar & getY() const
void publishRectFromMaskImage(ros::Publisher &pub, cv::Mat &image, const std_msgs::Header &header)
bool rectangleModeServiceCallback(std_srvs::EmptyRequest &req, std_srvs::EmptyResponse &res)
KEY_MODE stringToMode(const std::string &str)
bool polyModeServiceCallback(std_srvs::EmptyRequest &req, std_srvs::EmptyResponse &res)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
void infoCb(const sensor_msgs::CameraInfoConstPtr &msg)
cv::Point getLineEndPoint()
TFSIMD_FORCE_INLINE const tfScalar & y() const
void drawPoints(const image_view2::ImageMarker2::ConstPtr &marker, std::vector< CvScalar > &colors, std::vector< CvScalar >::iterator &col_it)
TFSIMD_FORCE_INLINE const tfScalar & getZ() const
V_ImageMarkerMessage marker_queue_
void addRegionPoint(int x, int y)
boost::mutex point_array_mutex_
static void mouseCb(int event, int x, int y, int flags, void *param)
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
bool isSelectingLineStartPoint()
std::vector< cv::Point2d > poly_points_
std::string tfFrame() const
TFSIMD_FORCE_INLINE const tfScalar & x() const
boost::mutex line_point_mutex_
ros::Publisher rectangle_pub_
TFSIMD_FORCE_INLINE tfScalar tfCos(tfScalar x)
cv::Mat distort_grid_mask_
void drawPoints3D(const image_view2::ImageMarker2::ConstPtr &marker, std::vector< CvScalar > &colors, std::vector< CvScalar >::iterator &col_it)
void drawText(const image_view2::ImageMarker2::ConstPtr &marker, std::vector< CvScalar > &colors, std::vector< CvScalar >::iterator &col_it)
void markerCb(const image_view2::ImageMarker2ConstPtr &marker)
void finishSelectingPoly()
void drawLineList3D(const image_view2::ImageMarker2::ConstPtr &marker, std::vector< CvScalar > &colors, std::vector< CvScalar >::iterator &col_it)
std::string getTopic() const
bool lineModeServiceCallback(std_srvs::EmptyRequest &req, std_srvs::EmptyResponse &res)
#define TFSIMD_RADS_PER_DEG
TFSIMD_FORCE_INLINE const tfScalar & z() const
#define DEFAULT_LINE_WIDTH
boost::mutex queue_mutex_
void publish(const sensor_msgs::Image &message) const
void processLeftButtonDown(int x, int y)
ros::Publisher background_mask_pub_
static void quaternionMsgToTF(const geometry_msgs::Quaternion &msg, Quaternion &bt)
ros::Publisher foreground_mask_pub_
bool fromCameraInfo(const sensor_msgs::CameraInfo &msg)
std::vector< cv::Point2d > point_array_
sensor_msgs::ImageConstPtr last_msg_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void drawLineStrip3D(const image_view2::ImageMarker2::ConstPtr &marker, std::vector< CvScalar > &colors, std::vector< CvScalar >::iterator &col_it)
void createDistortGridImage()
void drawInfo(ros::Time &before_rendering)
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
TFSIMD_FORCE_INLINE const tfScalar & y() const
const std::string TYPE_16UC1
image_transport::Publisher local_image_pub_
void processLeftButtonUp(int x, int y)
void imageCb(const sensor_msgs::ImageConstPtr &msg)
boost::shared_ptr< dynamic_reconfigure::Server< Config > > srv_
TFSIMD_FORCE_INLINE const tfScalar & x() const
boost::mutex poly_point_mutex_
bool changeModeServiceCallback(image_view2::ChangeModeRequest &req, image_view2::ChangeModeResponse &res)
void eventCb(const image_view2::MouseEvent::ConstPtr &event_msg)
void updatePolySelectingPoint(cv::Point p)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
image_transport::Publisher image_pub_
boost::format filename_format_
ros::ServiceServer poly_mode_srv_
#define ROS_DEBUG_STREAM(args)
image_geometry::PinholeCameraModel cam_model_
void publishMouseInteractionResult()
void drawPolygon3D(const image_view2::ImageMarker2::ConstPtr &marker, std::vector< CvScalar > &colors, std::vector< CvScalar >::iterator &col_it)
bool isValidMovement(const cv::Point2f &start_point, const cv::Point2f &end_point)
#define ROS_INFO_STREAM(args)
bool poly_selecting_done_
V_ImageMarkerMessage local_queue_
ros::Publisher move_point_pub_
bool grabcutRectModeServiceCallback(std_srvs::EmptyRequest &req, std_srvs::EmptyResponse &res)
bool region_continuous_publish_
void toROSMsg(const sensor_msgs::PointCloud2 &cloud, sensor_msgs::Image &image)
bool lookupTransformation(std::string frame_id, ros::Time &acquisition_time, std::map< std::string, int > &tf_fail, tf::StampedTransform &transform)
TFSIMD_FORCE_INLINE const tfScalar & getX() const
tf::TransformListener tf_listener_
void pointArrayToMask(std::vector< cv::Point2d > &points, cv::Mat &mask)
#define DEFAULT_CIRCLE_SCALE
TFSIMD_FORCE_INLINE tfScalar tfSin(tfScalar x)
cv::Point2d project3dToPixel(const cv::Point3d &xyz) const
void checkMousePos(int &x, int &y)
bool grabcutModeServiceCallback(std_srvs::EmptyRequest &req, std_srvs::EmptyResponse &res)
std::string getTopic() const
void updateLineStartPoint(cv::Point p)
void processMouseEvent(int event, int x, int y, int flags, void *param)
ros::ServiceServer grabcut_rect_mode_srv_
void processMove(int x, int y)
CvScalar MsgToRGB(const std_msgs::ColorRGBA &color)
std::vector< cv::Point2d > point_bg_array_
bool line_select_start_point_
ros::Subscriber event_sub_
ros::Publisher foreground_rect_pub_
ros::Subscriber marker_sub_
void publishForegroundBackgroundMask()
sensor_msgs::ImagePtr toImageMsg() const
cv::Point ratioPoint(double x, double y)
void drawCircle3D(const image_view2::ImageMarker2::ConstPtr &marker, std::vector< CvScalar > &colors, std::vector< CvScalar >::iterator &col_it)
ros::Publisher point_array_pub_