emc_system
src
maploader.cpp
Go to the documentation of this file.
1
#include "
emc/maploader.h
"
2
#include <yaml-cpp/yaml.h>
3
#include <
filesystem
>
4
5
MapData
loadmap
(
std::string
yaml_filename){
6
std::filesystem::path
yaml_filepath(yaml_filename);
7
YAML::Node config = YAML::LoadFile(yaml_filename);
8
9
double
resolution
= config[
"resolution"
].as<
double
>();
10
11
// find the image file
12
std::string
filename = config[
"image"
].as<
std::string
>();
13
std::filesystem::path
image_filepath = yaml_filepath;
14
image_filepath.
replace_filename
(filename);
15
if
(!
std::filesystem::exists
(image_filepath))
16
{
17
std::cerr
<<
"Image not found at "
<< image_filepath.string() <<
std::endl
;
18
return
MapData
();
19
}
20
21
cv::Mat map = cv::imread(image_filepath.string(), cv::IMREAD_GRAYSCALE);
22
if
(map.empty())
23
{
24
std::cerr
<<
"Failed to read image at "
<< image_filepath.string() <<
std::endl
;
25
return
MapData
();
26
}
27
28
MapData
mapdata;
29
mapdata.
map
= map;
30
mapdata.
resolution
=
resolution
;
31
return
mapdata;
32
}
MapData
Definition:
maploader.h:4
std::string
MapData::resolution
double resolution
Definition:
maploader.h:6
std::cerr
loadmap
MapData loadmap(std::string yaml_filename)
Definition:
maploader.cpp:5
MapData::map
cv::Mat map
Definition:
maploader.h:5
filesystem
std::filesystem::path
std::filesystem::path::replace_filename
T replace_filename(T... args)
std::endl
T endl(T... args)
resolution
double resolution
Definition:
visualize.cpp:9
maploader.h
std::filesystem::exists
T exists(T... args)
Generated on Wed Mar 12 2025 04:36:09 for emc_system by
1.8.17