一、grid_map_cv函数介绍
1.1 grid_map::GridMapCvConverter::initializeFromImage
功能:从图像初始化生成栅格地图
函数简介:
static bool grid_map::GridMapCvConverter::initializeFromImage ( const cv::Mat & image,
const double resolution,
grid_map::GridMap & gridMap,
const grid_map::Position & position
)
Initializes the geometry of a grid map from an image. This changes the geometry of the map and deletes all contents of the layers!
Parameters:
[in] image the image.
[in] resolution the desired resolution of the grid map [m/cell]. 栅格地图需要的分辨率
[out] gridMap the grid map to be initialized. 需要初始化的栅格地图
[in] optional) position the position of the grid map.
--栅格地图的位置-地图的原点的原点在栅格地图对应坐标系中的位置
--地图的原点为地图的左下角
--注:栅格地图右向为x轴正向,上为y轴正向
Returns:
true if successful, false otherwise.
其中grid_map::Position类型定义如下:
typedef Eigen::Vector2d Position;
函数定义:
static bool initializeFromImage(const cv::Mat& image, const double resolution,
grid_map::GridMap& gridMap, const grid_map::Position& position)
{
const double lengthX = resolution * image.rows;
const double lengthY = resolution * image.cols;
Length length(lengthX, lengthY);
gridMap.setGeometry(length, resolution, position);
return true;
}
1.2 grid_map::GridMap::setGeometry
设置栅格地图在指定坐标系下的位置
void grid_map::GridMap::setGeometry ( const Length & length,
const double resolution,
const Position & position = Position::Zero()
)
Set the geometry of the grid map. Clears all the data.
设置栅格地图的几何位置,并清除数据
Parameters:
length the side lengths in x, and y-direction of the grid map [m].
--x、y方向的长度
resolution the cell size in [m/cell].
--分辨率
position the 2d position of the grid map in the grid map frame [m].
--栅格地图在栅格地图坐标系中的位置
1.3 grid_map::GridMapCvConverter::addLayerFromImage
利用图像数据给栅格地图添加图层
#添加图层的数据类型,及通道数
template<typename Type_ , int NChannels_>
static bool grid_map::GridMapCvConverter::addLayerFromImage ( const cv::Mat & image,
const std::string & layer,
grid_map::GridMap & gridMap,
const float lowerValue = 0.0, //默认值
const float upperValue = 1.0, //默认值
const double alphaThreshold = 0.5 //默认值
) [inline, static]
Adds a layer with data from image. 从图像中添加一个有数据的层
Parameters:
[in] image the image to be added. If it is a color image (bgr or bgra encoding), it will be transformed in a grayscale image. 需要被添加的图像,其中彩色图会转为灰度图
[in] layer the layer that is filled with the image data. 需要添加图像数据的图层
[out] gridMap the grid map to be populated. 被填充的栅格地图
[in] optional) lowerValue value of the layer corresponding to black image pixels.
--图层一个栅格中值的最低值-对应图像的黑色像素
[in] optional) upperValue value of the layer corresponding to white image pixels.
--图层一个栅格中值的最大值-对应图像的白色像素
--图层一个栅格中值的范围应该在[lowerValue,upperValue]之间
[in] optional) alphaThreshold the threshold ([0.0, 1.0]) for the alpha value at which cells in the grid map are marked as empty.
--栅格地图某一栅格标记为空时的阈值(这么小的值,应该不是图像像素,是转化后的栅格地图值),改阈值范围为0~1
Returns:
true if successful, false otherwise.
1.4 grid_map::GridMap::get
返回图层数据,后续操作可能会改变图层数据
Matrix & grid_map::GridMap::get ( const std::string & layer )
Returns the grid map data for a layer as non-const. Use this method with care!
--返回栅格地图图层数据作为一个非常量,使用这种方法需要注意(是会改变图层数据吗?)
Parameters:
layer the name of the layer to be returned. --图层名称
Returns:
grid map data. 栅格地图格式数据
Exceptions:
std::out_of_range if no map layer with name `layer` is present.
--没有该图层时会输出
1.5 const Matrix & grid_map::GridMap::get
返回图层数据,应该不会改变图层的数据
const Matrix & grid_map::GridMap::get ( const std::string & layer ) const
Returns the grid map data for a layer as matrix.
Parameters:
layer the name of the layer to be returned.
Returns:
grid map data as matrix.
Exceptions:
std::out_of_range if no map layer with name `layer` is present.
1.6 grid_map::GridMapRosConverter::toOccupancyGrid
转换栅格地图指定图层为ros栅格地图数据类型
void grid_map::GridMapRosConverter::toOccupancyGrid ( const grid_map::GridMap & gridMap,
const std::string & layer,
float dataMin,
float dataMax,
nav_msgs::OccupancyGrid & occupancyGrid
) [static]
Parameters:
[in] gridMap the grid map object.
[in] layer the layer that is transformed to the occupancy cell data.
[in] dataMin the minimum value of the grid map data (used to normalize the cell data in [min, max]).
[in] dataMax the maximum value of the grid map data (used to normalize the cell data in [min, max]).
[out] occupancyGrid the message to be populated. 被填充的栅格地图的消息名
1.7 grid_map::GridMap::setTimestamp
设置栅格地图的时间戳
void grid_map::GridMap::setTimestamp ( const Time timestamp )
Set the timestamp of the grid map.
----设置栅格地图的时间戳(单位:纳秒)
Parameters:
timestamp the timestamp to set (in nanoseconds).
示例:
global_map.setTimestamp(ros::Time::now().toNSec());
二 grid_map类型定义
2.1 grid_map::Index
定义为:
typedef Eigen::Array2i Index;
参考下面,可以为两个int型的元组
template<typename Type >
using Eigen::Array2X = Array< Type, 2, Dynamic >
附录:
grid_map_cv官方文档介绍:grid_map_cv: File List
进入该网页不能够进行搜索查询,但可以在谷歌以“grid_map::xxx::xx”格式进行搜索
@meng