ed_sensor_integration
fitter_viz_data.cpp
Go to the documentation of this file.
1 #include <ed/entity.h>
2 #include <ed/world_model.h>
3 
4 #include <ed/kinect/fitter.h>
5 
6 #include <geolib/math_types.h>
7 
8 #include <opencv2/highgui/highgui.hpp>
9 
12 
13 
17 void usage()
18 {
19  std::cout << "Usage: ed_fitter IMAGE-FILE-OR-DIRECTORY WORLDMODEL_NAME ENTITY_ID" << std::endl;
20 }
21 
27 int main(int argc, char **argv)
28 {
29  if (argc != 4)
30  {
31  usage();
32  return 1;
33  }
34 
35  tue::filesystem::Path path = argv[1];
36  if (!path.exists())
37  {
38  std::cerr << "Path '" << path << "' does not exist." << std::endl;
39  return 1;
40  }
41  ed::SnapshotCrawler crawler(path);
42 
43  std::string model_name = argv[2];
44  ed::WorldModelPtr world_model;
45  try
46  {
47  world_model = ed::loadWorldModel(model_name);
48  }
49  catch (const ed::ModelNotFoundException& e)
50  {
51  std::cerr << "World model '" << model_name << "' could not be loaded." << std::endl;
52  std::cerr << e.what() << std::endl;
53  return 1;
54  }
55 
56  std::string entity_id = argv[3];
57  ed::EntityConstPtr e = world_model->getEntity(entity_id);
58  if (!e)
59  {
60  std::cerr << "Entity '" << entity_id << "' could not be found in world model '" << model_name << "'." << std::endl;
61  return 1;
62  }
63 
64  Fitter fitter;
65 
66  while(true)
67  {
68  ed::Snapshot& snapshot = crawler.current();
69 
70  FitterData fitterdata;
71  geo::Pose3D fitted_pose;
72 
73  fitter.configureBeamModel(snapshot.image->getCameraModel());
74  fitter.processSensorData(*snapshot.image, snapshot.sensor_pose, fitterdata);
75 
76  bool estimateEntityPose = fitter.estimateEntityPose(fitterdata, *world_model, entity_id, e->pose(), fitted_pose);
77 
78  // poses for visualization
79  geo::Transform2 sensor_pose2d = fitterdata.sensor_pose_xya.projectTo2d();
80  geo::Transform2 entity_pose2d = e->pose().projectTo2d();
81  geo::Transform2 fitted_pose2d = fitted_pose.projectTo2d();
82 
83  // show snapshot
84  cv::Mat rgbcanvas = snapshot.image->getRGBImage();
85  cv::imshow("RGB", rgbcanvas);
86 
87  EntityRepresentation2D entity_2d = fitter.GetOrCreateEntity2D(e);
88  cv::Mat canvas = visualizeFitting(entity_2d, sensor_pose2d, entity_pose2d, fitted_pose2d, fitterdata, estimateEntityPose);
89  cv::imshow("Fitting", canvas);
90  char key = cv::waitKey();
91 
92  if (key == 81) // Left arrow
93  {
94  crawler.previous();
95  }
96  else if (key == 83) // Right arrow
97  {
98  crawler.next();
99  }
100  else if (key == 82) // Up arrow
101  {
103  }
104  else if (key == 84) // Down arrow
105  {
107  }
108  else if (key == 'q')
109  {
110  break;
111  }
112  }
113  cv::destroyAllWindows();
114  return 0;
115 }
std::string
ed::Snapshot
The Snapshot struct, of a camera image taken at a single point in time.
Definition: snapshot.h:47
fitter_viz.h
ed::Snapshot::sensor_pose
geo::Pose3D sensor_pose
Definition: snapshot.h:50
tue::filesystem::Path
FitterData::sensor_pose_xya
geo::Pose3D sensor_pose_xya
Definition: fitter.h:73
std::cerr
tue::filesystem::Path::exists
bool exists() const
geo::Transform3T
Fitter::estimateEntityPose
bool estimateEntityPose(const FitterData &data, const ed::WorldModel &world, const ed::UUID &id, const geo::Pose3D &expected_pose, geo::Pose3D &fitted_pose, double max_yaw_change=M_PI) const
estimateEntityPose performs the entity pose estimation. Basically, tries to call estimateEntityPoseIm...
Definition: fitter.cpp:258
ed::loadWorldModel
ed::WorldModelPtr loadWorldModel(const std::string &model_name)
Definition: snapshot.h:115
FitterData
The FitterData struct contains the downprojected (hence 2D) sensor readings as well as the sensor pos...
Definition: fitter.h:68
EntityRepresentation2D
The EntityRepresentation2D struct contains the (downprojected) shape that is used for the fitting.
Definition: fitter.h:55
ed::EntityConstPtr
shared_ptr< const Entity > EntityConstPtr
std::cout
ed::SnapshotCrawler
Definition: snapshot.h:137
Fitter::GetOrCreateEntity2D
EntityRepresentation2D GetOrCreateEntity2D(const ed::EntityConstPtr &e) const
GetOrCreateEntity2D returns the downprojected shape of the entity. If it's already in the cache,...
Definition: fitter.cpp:528
ed::SnapshotCrawler::next
void next()
next, proceed to next index of the snapshot list. If index is out of bounds, try to load a new snapsh...
Definition: snapshot.h:168
geo::Transform2T
ed::SnapshotCrawler::previous
void previous()
Definition: snapshot.h:159
ed::WorldModelPtr
shared_ptr< WorldModel > WorldModelPtr
ed::Snapshot::image
rgbd::ImagePtr image
Definition: snapshot.h:49
visualizeFitting
cv::Mat visualizeFitting(EntityRepresentation2D entity, geo::Transform2 sensor_pose, geo::Transform2 entity_pose, geo::Transform2 fitted_pose, FitterData fitterdata, bool estimateEntityPose)
Definition: fitter_viz.h:114
geo::Transform3T::projectTo2d
Transform2T< T > projectTo2d() const
world_model.h
std::endl
T endl(T... args)
snapshot.h
ed::SnapshotCrawler::current
Snapshot & current()
Definition: snapshot.h:156
fitter.h
canvas_resolution
float canvas_resolution
Definition: fitter_viz.h:17
Fitter::configureBeamModel
void configureBeamModel(const image_geometry::PinholeCameraModel &cammodel)
configure the beam model (nr of data points and focal length) according to the camera you are using.
Definition: fitter.cpp:475
Fitter::processSensorData
void processSensorData(const rgbd::Image &image, const geo::Pose3D &sensor_pose, FitterData &data) const
processSensorData pre-processes sensor data, i.e., performs a downprojection of the input depth image...
Definition: fitter.cpp:486
std::max
T max(T... args)
Fitter
The Fitter class contains the algorithm to do the 2D fit of an entity.
Definition: fitter.h:100
math_types.h
entity.h
ed::ModelNotFoundException
Definition: snapshot.h:29
main
int main(int argc, char **argv)
main executable to visualise the fitting process of stored images.
Definition: fitter_viz_data.cpp:27
usage
void usage()
usage, print how the executable should be used and explain the input
Definition: fitter_viz_data.cpp:17
ed::ModelNotFoundException::what
const char * what() const
Definition: snapshot.h:39