40 #include <opencv2/imgproc/imgproc.hpp> 42 #include <QMessageBox> 44 #include <opencv/cv.h> 45 #include <opencv/highgui.h> 46 #include <geometry_msgs/Transform.h> 47 #include "hector_mapstitch/mapstitch.h" 48 #include "hector_mapstitch/utils.h" 49 #include <std_msgs/String.h> 58 setObjectName(
"MapMerger");
63 std::cout <<
"started map merging plugin " <<std::endl;
73 ui_.map2_label->installEventFilter(
this);
74 ui_.map1_label->installEventFilter(
this);
89 connect(
ui_.map_hector1_horizontalSlider, SIGNAL(valueChanged(
int)),
this, SLOT(
onSlider1Moved(
int)));
90 connect(
ui_.map_hector2_horizontalSlider, SIGNAL(valueChanged(
int)),
this, SLOT(
onSlider2Moved(
int)));
94 connect(
ui_.store_current_transform_button, SIGNAL(pressed()),
this, SLOT(
onGetTransform()));
107 std::stringstream sstr;
110 ui_.stored_transform_text->setText(sstr.str().c_str());
120 ui_.map_hector1_horizontalSlider->setRange(0,
qimages_1_.size()-1);
121 ui_.map_hector2_horizontalSlider->setRange(0,
qimages_2_.size()-1);
129 std::stringstream sstr;
132 ui_.map_1_text->setText(sstr.str().c_str());
139 std::stringstream sstr;
142 ui_.map_2_text->setText(sstr.str().c_str());
161 std::stringstream sstr;
164 ui_.stored_transform_text->setText(sstr.str().c_str());
168 std_msgs::String geo_string;
169 geo_string.data =
"savegeotiff";
180 ui_.map1_label->setPixmap(QPixmap::fromImage(image_scaled));
186 ROS_INFO(
"no map for robot1 known");
200 ui_.map2_label->setPixmap(QPixmap::fromImage(image_scaled));
204 ROS_INFO(
"no map for robot2 known");
222 if(stitched_map.isValid())
224 ui_.merge_button->setText(
"merging ...");
225 cv::Mat stitched_cv_map = stitched_map.get_stitch();
226 ui_.merge_button->setText(
"merge");
228 stitched_cv_map.convertTo(gray, CV_8UC1);
230 cv::cvtColor(gray, temp, CV_GRAY2RGB);
233 QImage image(temp.data, temp.cols, temp.rows, QImage::Format_RGB888);
234 QImage image_scaled = image.scaled(
ui_.merged_map_label->width(),
ui_.merged_map_label->height(), Qt::IgnoreAspectRatio );
235 ui_.merged_map_label->setPixmap(QPixmap::fromImage(image_scaled));
268 return QObject::eventFilter(watched, event);
280 map1_cv.convertTo(gray, CV_8UC1);
304 map2_cv.convertTo(gray, CV_8UC1);
326 nav_msgs::OccupancyGrid map;
328 map.info.height = im->rows;
329 map.info.width = im->cols;
331 map.data.resize(map.info.width * map.info.height);
333 for(
size_t i = 0; i < map.data.size(); ++i)
335 uint8_t map_val = im->data[i];
336 if(map_val == 0) map.data[i] = 100;
337 else if(map_val == 254) map.data[i] = 0;
338 else map.data[i] = -1;
347 uint8_t *data = (uint8_t*) map->data.data(),
349 bool mapHasPoints =
false;
351 cv::Mat im(map->info.height, map->info.width, CV_8UC1);
354 for (
size_t i=0; i<map->data.size(); i++)
356 if (data[i] == 0) im.data[i] = 254;
357 else if (data[i] == 100) im.data[i] = 0;
358 else im.data[i] = 205;
361 if (i!=0) mapHasPoints = mapHasPoints || (data[i] != testpoint);
366 if (!mapHasPoints) {
ROS_WARN(
"map is empty, ignoring update."); }
ros::Publisher map_2_to_use_pub_
bool eventFilter(QObject *watched, QEvent *event)
virtual void shutdownPlugin()
ros::Timer map_save_timer_
std::vector< QImage > qimages_1_
ros::Publisher map_1_to_use_pub_
void publish(const boost::shared_ptr< M > &message) const
void onSlider1Moved(int idx)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::vector< cv::Mat > cv_maps_2_
std::vector< QImage > qimages_2_
std::vector< cv::Mat > cv_maps_1_
nav_msgs::OccupancyGrid og_map_1_
void addWidget(QWidget *widget)
nav_msgs::OccupancyGrid og_map_2_
cv::Mat occupancyGridToCvMat(const nav_msgs::OccupancyGrid *map)
cv::Mat current_transform
bool use_stored_transform_
void redraw_Label_merged()
std::vector< nav_msgs::OccupancyGrid > og_maps_1_
ros::Publisher hector_command_pub_
void map2Callback(nav_msgs::OccupancyGridConstPtr const &map)
void timerCallback(const ros::TimerEvent &e)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Subscriber map_2_sub_
void map1Callback(nav_msgs::OccupancyGridConstPtr const &map)
virtual void initPlugin(qt_gui_cpp::PluginContext &context)
void onStateUseTransformChanged(int checked)
void onSlider2Moved(int idx)
ros::Subscriber map_1_sub_
void onSaveGeotiffPressed()
nav_msgs::OccupancyGrid cvMatToOccupancyGrid(const cv::Mat *im)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
std::vector< nav_msgs::OccupancyGrid > og_maps_2_