39 #include <boost/filesystem.hpp> 40 #include <opencv2/core/core.hpp> 41 #include <opencv2/highgui/highgui.hpp> 56 private_nh.
param(
"topic", topic, std::string(
"map"));
57 private_nh.
param(
"nav_grid", use_nav_grid,
false);
63 ROS_FATAL_NAMED(
"MapSaver",
"write_unstamped and write_stamped both set to false. Nothing will be written.");
68 private_nh.
param(
"trinary_output", trinary_output,
true);
80 std::string output_directory_str;
81 private_nh.
param(
"output_directory", output_directory_str, std::string(
"."));
88 catch (
const std::exception& e)
91 "Error: " + e.what());
102 boost::filesystem::path output;
109 std::stringstream ss;
110 ss <<
map_prefix_ <<
"-" << std::setw(10) << std::setfill(
'0') << stamp.
sec <<
"." << extension;
123 for (
unsigned int row = 0; row < info.
height; ++row)
125 unsigned char* output_row = image.ptr<
unsigned char>(row);
126 for (
unsigned int col = 0; col < info.
width; ++col)
128 unsigned char input =
data_(col, info.
height - row - 1);
150 cv::imwrite(map_path.string(), image);
154 std::ofstream yaml_file(yaml_path.c_str(), std::ofstream::out);
155 if (yaml_file.is_open())
157 yaml_file <<
"image: " << map_path.filename().string() <<
"\n";
158 yaml_file <<
"resolution: " << info.
resolution <<
"\n";
159 yaml_file <<
"origin: [" << info.
origin_x <<
", " << info.
origin_y <<
", 0]\n";
160 yaml_file <<
"occupied_thresh: 0.65\n";
161 yaml_file <<
"free_thresh: 0.196\n";
162 yaml_file <<
"negate: 0\n";
187 int main(
int argc,
char** argv)
#define ROS_INFO_NAMED(name,...)
std::string map_extension_
nav_grid::VectorNavGrid< unsigned char > data_
std::string toString() const
void setCostInterpretation(const std::vector< NumericType > &cost_interpretation_table)
NumericType interpretCost(IntegralType original_value, const std::vector< NumericType > &cost_interpretation_table)
boost::filesystem::path output_directory_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void newDataCallback(const nav_core2::UIntBounds &bounds)
static std::vector< unsigned char > TRINARY_SAVE
int main(int argc, char **argv)
static std::vector< unsigned char > SCALE_SAVE
nav_grid_pub_sub::NavGridSubscriber map_sub_
void writeData(const ros::Time &stamp, const cv::Mat &image, const nav_grid::NavGridInfo &info) const
#define ROS_FATAL_STREAM(args)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
boost::filesystem::path generatePath(const std::string &extension, const ros::Time &stamp) const
void init(ros::NodeHandle &nh, NewDataCallback callback, const std::string &topic="map", bool nav_grid=true, bool subscribe_to_updates=true)
#define ROS_WARN_STREAM_THROTTLE(rate, args)
std::vector< unsigned char > getOccupancyInput(bool trinary=false, bool use_unknown_value=false)
std::vector< unsigned char > output_interpretation_
NavGridInfo getInfo() const
#define ROS_FATAL_NAMED(name,...)
ROSCPP_DECL void spinOnce()