GridMapCvProcessing.cpp
Go to the documentation of this file.
1 /*
2  * GridMapCvProcessing.cpp
3  *
4  * Created on: Apr 15, 2016
5  * Author: Péter Fankhauser
6  * Institute: ETH Zurich, ANYbotics
7  */
8 
11 
12 namespace grid_map {
13 
15 {
16 }
17 
19 {
20 }
21 
23  GridMap& gridMapResult,
24  const double resolution,
25  const int interpolationAlgorithm)
26 {
27  GridMap gridMapSourceCopy(gridMapSource);
28  gridMapSourceCopy.convertToDefaultStartIndex();
29  const double sizeFactor = gridMapSourceCopy.getResolution() / resolution;
30  bool firstLayer = true;
31  for (const auto& layer : gridMapSourceCopy.getLayers()) {
32  cv::Mat imageSource, imageResult;
33  const float minValue = gridMapSourceCopy.get(layer).minCoeffOfFinites();
34  const float maxValue = gridMapSourceCopy.get(layer).maxCoeffOfFinites();
35  const bool hasNaN = gridMapSourceCopy.get(layer).hasNaN();
36  bool result;
37  if (hasNaN) {
38  result = GridMapCvConverter::toImage<unsigned short, 4>(gridMapSourceCopy, layer, CV_16UC4, minValue, maxValue, imageSource);
39  } else {
40  result = GridMapCvConverter::toImage<unsigned short, 1>(gridMapSourceCopy, layer, CV_16UC1, minValue, maxValue, imageSource);
41  }
42  if (!result) return false;
43  cv::resize(imageSource, imageResult, cv::Size(0.0, 0.0), sizeFactor, sizeFactor, interpolationAlgorithm);
44  if (firstLayer) {
45  if (!GridMapCvConverter::initializeFromImage(imageResult, resolution, gridMapResult, gridMapSourceCopy.getPosition()))
46  return false;
47  firstLayer = false;
48  }
49  if (hasNaN) {
50  result = GridMapCvConverter::addLayerFromImage<unsigned short, 4>(imageResult, layer, gridMapResult, minValue, maxValue);
51  } else {
52  result = GridMapCvConverter::addLayerFromImage<unsigned short, 1>(imageResult, layer, gridMapResult, minValue, maxValue);
53  }
54  if (!result) return false;
55  }
56  gridMapResult.setFrameId(gridMapSourceCopy.getFrameId());
57  gridMapResult.setTimestamp(gridMapSourceCopy.getTimestamp());
58  gridMapResult.setBasicLayers(gridMapSourceCopy.getBasicLayers());
59  return true;
60 }
61 
62 } /* namespace */
Time getTimestamp() const
bool getPosition(const Index &index, Position &position) const
void setBasicLayers(const std::vector< std::string > &basicLayers)
const std::string & getFrameId() const
static bool initializeFromImage(const cv::Mat &image, const double resolution, grid_map::GridMap &gridMap, const grid_map::Position &position)
void convertToDefaultStartIndex()
double getResolution() const
const std::vector< std::string > & getLayers() const
const Matrix & get(const std::string &layer) const
static bool changeResolution(const GridMap &gridMapSource, GridMap &gridMapResult, const double resolution, const int interpolationAlgorithm=cv::INTER_CUBIC)
void setFrameId(const std::string &frameId)
void setTimestamp(const Time timestamp)
const std::vector< std::string > & getBasicLayers() const


grid_map_cv
Author(s): Péter Fankhauser
autogenerated on Tue Jun 25 2019 20:02:13