GridMapCvProcessing.cpp
Go to the documentation of this file.
00001 /*
00002  * GridMapCvProcessing.cpp
00003  *
00004  *  Created on: Apr 15, 2016
00005  *      Author: Péter Fankhauser
00006  *       Institute: ETH Zurich, ANYbotics
00007  */
00008 
00009 #include "grid_map_cv/GridMapCvProcessing.hpp"
00010 #include "grid_map_cv/GridMapCvConverter.hpp"
00011 
00012 namespace grid_map {
00013 
00014 GridMapCvProcessing::GridMapCvProcessing()
00015 {
00016 }
00017 
00018 GridMapCvProcessing::~GridMapCvProcessing()
00019 {
00020 }
00021 
00022 bool GridMapCvProcessing::changeResolution(const GridMap& gridMapSource,
00023                              GridMap& gridMapResult,
00024                              const double resolution,
00025                              const int interpolationAlgorithm)
00026 {
00027   GridMap gridMapSourceCopy(gridMapSource);
00028   gridMapSourceCopy.convertToDefaultStartIndex();
00029   const double sizeFactor = gridMapSourceCopy.getResolution() / resolution;
00030   bool firstLayer = true;
00031   for (const auto& layer : gridMapSourceCopy.getLayers()) {
00032     cv::Mat imageSource, imageResult;
00033     const float minValue = gridMapSourceCopy.get(layer).minCoeffOfFinites();
00034     const float maxValue = gridMapSourceCopy.get(layer).maxCoeffOfFinites();
00035     const bool hasNaN = gridMapSourceCopy.get(layer).hasNaN();
00036     bool result;
00037     if (hasNaN) {
00038       result = GridMapCvConverter::toImage<unsigned short, 4>(gridMapSourceCopy, layer, CV_16UC4, minValue, maxValue, imageSource);
00039     } else {
00040       result = GridMapCvConverter::toImage<unsigned short, 1>(gridMapSourceCopy, layer, CV_16UC1, minValue, maxValue, imageSource);
00041     }
00042     if (!result) return false;
00043     cv::resize(imageSource, imageResult, cv::Size(0.0, 0.0), sizeFactor, sizeFactor, interpolationAlgorithm);
00044     if (firstLayer) {
00045       if (!GridMapCvConverter::initializeFromImage(imageResult, resolution, gridMapResult, gridMapSourceCopy.getPosition()))
00046         return false;
00047       firstLayer = false;
00048     }
00049     if (hasNaN) {
00050       result = GridMapCvConverter::addLayerFromImage<unsigned short, 4>(imageResult, layer, gridMapResult, minValue, maxValue);
00051     } else {
00052       result = GridMapCvConverter::addLayerFromImage<unsigned short, 1>(imageResult, layer, gridMapResult, minValue, maxValue);
00053     }
00054     if (!result) return false;
00055   }
00056   gridMapResult.setFrameId(gridMapSourceCopy.getFrameId());
00057   gridMapResult.setTimestamp(gridMapSourceCopy.getTimestamp());
00058   gridMapResult.setBasicLayers(gridMapSourceCopy.getBasicLayers());
00059   return true;
00060 }
00061 
00062 } /* namespace */


grid_map_cv
Author(s): Péter Fankhauser
autogenerated on Tue Jul 9 2019 05:06:24