voronoi_path_generator.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <nav_msgs/OccupancyGrid.h>
5 #include <memory>
6 #include <opencv/cv.hpp>
7 #include <queue>
8 #include <string>
9 
10 using namespace cv;
11 
12 namespace voronoi_map
13 {
14 
15  VoronoiPathGenerator::VoronoiPathGenerator()
16  {
17 
18  }
19 
20  void VoronoiPathGenerator::prepareMap(const Mat& _map, Mat& _smoothedMap, int blurSize)
21  {
22  static Mat srcMap;
23  _map.convertTo(srcMap, CV_8UC1);
24 
25  for(int i = 0; i < srcMap.cols * srcMap.rows; i++)
26  {
27  if((signed char)_map.data[i] < 0)
28  srcMap.data[i] = 100;
29  }
30 
31  _smoothedMap = srcMap;
32 
33  try
34  {
35  if(blurSize > 0)
36  {
37  cv::Size sz(blurSize, blurSize);
38  cv::GaussianBlur(srcMap, srcMap, sz, 0);
39  cv::GaussianBlur(srcMap, srcMap, sz, 0);
40  }
41  }
42  catch(...)
43  {
44  // if opencv fails to smooth continue
45  ROS_INFO("Smoothing map failed");
46  }
47 
48  cv::bitwise_not(srcMap, srcMap);
49  cv::threshold(srcMap, _smoothedMap, 10, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);
50  }
51 
52 
53  void VoronoiPathGenerator::computeDistanceField(const cv::Mat& _map, cv::Mat& _distField)
54  {
55  cv::distanceTransform(_map, _distField, CV_DIST_L2, 3);
56  }
57 
58  void VoronoiPathGenerator::computeVoronoiMap(const cv::Mat& _distField, cv::Mat& _voronoiMap)
59  {
60  Mat srcMap = _distField;
61  srcMap.convertTo(_voronoiMap, CV_8UC1, 0.0);
62 
63  voronoi_map::greyscale_thinning(srcMap, _voronoiMap);
64  cv::threshold(_voronoiMap, _voronoiMap, 1, 255, CV_THRESH_BINARY);
65  voronoi_map::sceletonize(_voronoiMap, _voronoiMap);
66  }
67 }
void greyscale_thinning(const cv::Mat &src, cv::Mat &dst)
Function for finding the ridge of a distance graph.
Definition: thinning.cpp:109
void sceletonize(const cv::Mat &src, cv::Mat &dst)
Function for thinning the given binary image (Paper Zhang-Suen Thinning)
Definition: thinning.cpp:85
#define ROS_INFO(...)


tuw_voronoi_graph
Author(s): Benjamin Binder
autogenerated on Mon Jun 10 2019 15:42:44